Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Recursive Directory Tree Deletion in Windows

by the_slycer (Chaplain)
on Oct 18, 2000 at 17:39 UTC ( [id://37369]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Recursive Directory Tree Deletion in Windows

As it happens I was working on something similar to this last nite. I spent a couple of hours on it before I discovered File::Find - I really have to read more, might be able to stop duplicating effort. Anyhow, here is the code that I wrote, someone let me know what problems there are.. other than the obvious dup of effort :-).
use strict; unless ($ARGV[0]){ print "Please enter a string to look for: "; $ARGV[0]=<STDIN>; chomp @ARGV; } my $delkey = $ARGV[0]; my $startdir="c:/blah"; my (@dirs, @newdirs, @dellist); print "searching $startdir\n"; #build a list of files/dirs: my @list = glob("$startdir*"); #run through the list, if a dir, goes to @dir array (with a / at the e +nd) foreach (@list){ push (@dirs => "$_/") if -d; if (/.*$delkey*/oi){ push (@dellist => "$_/") if -d; } } #call the subroutine - this does the same thing on the next set of dir +s down build(@dirs); #if there are further subdirs, call the sub again while (@newdirs){ build($newdirs[0]); shift(@newdirs); } sub build{ my @dirs=@_; while (@dirs){ my $dir = shift (@dirs); print "searching $dir\n"; my @list = glob("$dir*"); foreach (@list){ push (@newdirs => "$_/") if -d; if (/.*$delkey*/oi){ push (@dellist => "$_/") if -d; } } } } foreach (reverse @dellist){ print "found: $_ to delete\n"; chdir "$_" || die "Unable to change to $_ : $!"; unlink (<*>); chdir "$startdir" || die "Unable to change back to $startdir : $!" +; rmdir "$_" || die "Unable to rmdir on $_ : $!"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://37369]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.