If you want to delete files from a directory tree, the File::Path module has an rmtree 
command.

--Chuck

--- "DePriest, Jason R." <[EMAIL PROTECTED]> wrote:
> You can use slightly ugly recursive code.. I use the following to delete
> files from the temp directories recursively, but it could be easily modified
> to copy them:
> 
> #!perl -s
> use Cwd;
> 
> if (! &AlreadyExist("$ENV{TMP}")) {
>       push(@TempDirs,"$ENV{TMP}");
> }
> if (! &AlreadyExist("$ENV{TEMP}")) {
>       push(@TempDirs,"$ENV{TEMP}");
> }
> if (! &AlreadyExist("$ENV{WINDIR}\\TEMP")) {
>       push(@TempDirs,"$ENV{WINDIR}\\TEMP");
> }
> if (! &AlreadyExist("$ENV{SystemRoot}\\TEMP")) {
>       push(@TempDirs,"$ENV{SystemRoot}\\TEMP");
> }
> if (! &AlreadyExist("$ENV{SystemDrive}\\TEMP")) {
>       push(@TempDirs,"$ENV{SystemDrive}\\TEMP");
> }
> print "Found these temporary directories on your system:\n";
> print join "\n",@TempDirs;
> print "\n\nPress <ENTER> to continue the script\n";
> print "or Press <CTRL>-C to exit the script immediately: ";
> $garbage = <STDIN>;
> 
> foreach $Dir (@TempDirs) {
>       if (-e $Dir and -d $Dir) {
>               print "\n-> Looking in directory $Dir\n";
>               &ScanDir("$Dir");
>       } # end of if
> } # end of foreach
> 
> print "\n\nPress <ENTER> to exit the script: ";
> $garbage = <STDIN>;
> exit;
> 
> sub AlreadyExist {
>       my $CurrentDir = $_[0];
>       $equal = 0;
>       foreach $Dir (@TempDirs) {
>               if ($Dir eq $CurrentDir) {
>                       $equal = 1;
>               } # end of if
>       } # end of foreach
>       return $equal;
> } # end of sub AlreadyExist
> 
> sub ScanDir {
>       my ($workdir) = shift; 
>       my ($startdir) = &cwd; # keep track of where we began
> 
>       chdir($workdir) or die "\nUnable to enter dir $workdir:$!\n";
>       opendir(DIR, ".") or die "\nUnable to open $workdir:$!\n";
>       my @names = readdir(DIR) or die "\nUnable to read $workdir:$!\n";
>       closedir(DIR);
> 
>               foreach my $name (@names) {
>               next if ($name eq ".");
>               next if ($name eq "..");
>               if (-d $name) { # is this a directory?
>                       print "\n-> Looking in directory $name";
>                       &ScanDir($name);
>                       print "\nAttemtping to delete directory $name";
>                       rmdir($name) or warn "\nUnable to remove directory
> $name: $!\n";
>                       next;
>               } # end of if
>               if ($name ne "") {
>                       print "\nAttemtping to delete file $name";
>                       unlink($name) or warn "\nUnable to delete file
> $name: $!\n";
>               } # end of if
>       } # end of foreach
>       chdir($startdir) or die "\nUnable to change to dir $startdir: $!\n";
> } # end of sub ScanDir
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - send holiday greetings for Easter, Passover
http://greetings.yahoo.com/
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to