用perl来删除所有以.temp结尾的文件的代码,供大家学习参考。
#在c:查找findfile.pl文件
#!/usr/bin/perl -w
use strict;
use File::Find;
sub wanted {
if ($_ eq "findfile.pl") {
print $File::Find::name;
}
}
find (&wanted,'c:/');
#在c:下删除所有以.temp结尾的文件
#!/usr/bin/perl -w
use strict;
use File::Find;
sub wanted {
if (-f $File::Find::name) {
if ($File::Find::name=~/.temp$/) {
print "Removing $File::Find::namen";
unlink $File::Find::name;
}
}
}
find (&wanted,'c:/');
#!/usr/bin/perl -w
use strict;
use File::Find;
print "Starting to clean all .keep file in current directory:n";
sub wanted {
if (-f $File::Find::name) {
if ($File::Find::name=~/.keep$/) {
print "Removing $File::Find::namen";
unlink $File::Find::name;
}
}
}
find (&wanted,'c:/','d:/','e:/');