I am so mean, that I even give the script away now.
I think that you really should keep voting me down! (there are always going to be things that I won't understand in the world, even in nice places like PM:-( )
Note: the script might have to be run several times, because it does not delete directories when they still have files in them. - Just keep running it until 0 file and 0 directory are deleted.
#!/usr/local/bin/perl -w
use File::Find;
$workingdir = 'C:/TEMP/';
$countdirs = 0;
$countfiles = 0;
$testmode = 0;
@extensions = ('txt','obj'); #files to remove
@directories = ('win32-VC60','CVS','Cvs'); #directories to remove (rec
+ursively with all the files/subs in them)
@anymatches = ('ChangeLog'); #other special matches to remove as well
find(\&processmatch, $workingdir);
print "\n$countfiles file(s) and $countdirs director(y)(ies) were dele
+ted.\n\n";
sub processmatch{
# Note: we are chdir in the current directory!
$saved = $_;
$name = $File::Find::name;
$deleteflag = 0;
foreach $ext(@extensions)
{
if($name =~ /.*\.$ext/)
{
$deleteflag = 1;
}
}
foreach $dir(@directories)
{
if($name =~ /.*\/$dir.*/)
{
$deleteflag = 1;
}
}
foreach $any(@anymatches)
{
if($name =~ /.*$any.*/)
{
$deleteflag = 1;
}
}
if($deleteflag == 1)
{
if (-d $name)
{
if(!$testmode)
{
rmdir $name;
}
print "$name\n";
$countdirs++;
}
else
{
if(!$testmode)
{
unlink $saved;
}
print "$saved\n";
$countfiles++;
}
}
$_ = $saved;
}
BTW: Thanks for the persons who helped me!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.