Perl implementation deletes a picture cache thumbnail under Windows Thumbs.db_perl

Source: Internet
Author: User
Tags svn

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.