You tend (%90+ time) to "shoot yourself in the foot" when you try to do too many things at once (like run a marathon, whilst talking on your cellphone, and balancing a book on your head, with your pants around your ankles, orr, drive whilst carrying on a conversation with someone in the back seat and someone on the phone, all whilst eating a giant sandwich)
So, what you want to do, what you need to do, if you wish to be able to walk after you run your program, is gather a list of the files in whatever directory you wish to play in, and this can be accomplished using File::Find or simply with the readdir function (I suggest File::Find if you need to recurse infinetly deep... for most situations)
After you have a list of *potential* deletion candidates, you need to weed out the ones you want (or if it's easier, the ones you wish to keep).
You can either push the qualifying candidates onto an array, and unlink all of them at once, or just delete them when you detect one.
I'd personally use File::Find for the job, and *qualify* and unlink a candidate in one function (commonly called &wanted), especially if you got lots of subdirectories and stuff (cause if you don't have a *full* path, you have to chdir, which File::Find does for you).
Here is some authentic looking pseudocode.
#!/usr/bin/perl -wT use strict; use File::Find; undef %ENV; &find(\&wanted,'/some/path/stuff'); print "all done\n"; exit(1); ## s u b l a n d sub wanted { my $fn = $_; # filename if ( -f $fn) # it's a file { if ( /somepattern/ and /somepattern/ and not /somepatter/) { printf "unlinking $fn (1 == success) ... %s\n", unlink $fn; } } }
___crazyinsomniac_______________________________________
Disclaimer: Don't blame. It came from inside the void
perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"
In reply to (crazyinsomniac: strategy) Re2: unlinking multiple files at once
by crazyinsomniac
in thread unlinking multiple files at once
by krose
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |