Take over the project that others did before, found SVN in the ignore did not deal with the *.db, resulting in the image cached thumbnail files are submitted, and I just open the picture folder, it means that thumbs.db has changed.
There are two things to do:
First, change SVN settings, no longer submit thumbs.db files
Second, bulk delete the specified directory of thumbs.db files
So in Perl, the code was modified in the previous Perl traversal directory, with two points of attention:
First, the file path, Windows defaults to "\" and Linux is "/", so the unified change to "/"
Two, compare two string equality need to use EQ instead of = = (= return numeric equality, and EQ return is string equality)
Third, unlink delete files, you need to specify the full path of the file
D. Else if in Perl is elsif without that "e"
Perl Regular matching mode is =~ or!~
The complete code is as follows, and you need to change the rule to modify this section in the code:
Copy Code code as follows:
#!/usr/bin/perl
Use strict;
Use warnings;
My $path = "c:/flexapp/xx";
my $filecount = 0;
Sub Parse_env {
My $path = $_[0]; #或者使用 my ($path) = @_; @_ similar to arguments in JavaScript
My $subpath;
My $handle;
if (-D $path) {#当前路径是否为一个目录
if (Opendir ($handle, $path)) {
while ($subpath = Readdir ($handle)) {
if (!) ( $subpath =~ m/^\.$/) and! ($subpath =~ m/^ (\.\.) $/)) {
My $p = $path. " /$subpath ";
if (-D $p) {
Parse_env ($p);
} elsif ($subpath eq "Thumbs.db") {
+ + $filecount;
Print "The file path:". $p. " ------------the file name: $subpath \ n ";
Unlink ($p) or warn "failed on $subpath: $!";
}
}
}
Closedir ($handle);
}
}
return $filecount;
}
My $count = parse_env $path;
My $str = "Total number of deleted files:". $count;
Print $str;
Results of output from console: