
Michael
Deleted
May 27, 2000, 12:27 PM
Post #3 of 7
(6706 views)
|
Re: Simple tricks for deleting directories/files
[In reply to]
|
Can't Post
|
|
Yep, I ended up doing this: sub Delete_Stuff { @filetype = ('*.*'); foreach $row(@in) { ($Name, $Value) = split ("=", $row); $Name = &decodeURL($Name); $Value = &decodeURL($Value); ($Trash, $ForumNumber) = split(/\|\|\|/, $Name); push (@AdjustForums, $ForumNumber); print "$Trash, $ForumNumber, $Value <br>"; if ($Trash eq "DelForum") { $Num = $Value; print "<br>Forum Path $ForumsPath/Forum$Num<br>"; $dir = "$ForumsPath/Forum$Num"; $days = 1; opendir DIR, $dir or print "can't open $dir: $!<BR>"; while (defined ($file = readdir DIR)) { next if $file eq "." or $file eq ".."; $next = "$dir/$file"; push(@files, $next); push(@all_files, $next); } foreach $files(@files) { opendir(DIR2, "$files") | | print "can't open $files: $!<BR>"; while (defined ($file2 = readdir DIR2)) { next if $file2 eq "." or $file2 eq ".."; $next2 = "$files/$file2"; push(@files2, $next2); push(@all_files, $next2); } } foreach $files2(@files2) { opendir(DIR3, "$files2") | | print "can't open $files2: $!<BR>"; while (defined ($file3 = readdir DIR3)) { next if $file3 eq "." or $file3 eq ".."; $next3 = "$files2/$file3"; push(@files3, $next3); push(@all_files, $next3); } } foreach $files3(@files3) { opendir(DIR3, "$files3") | | print "can't open $files3: $!<BR>"; while (defined ($file4 = readdir DIR4)) { next if $file4 eq "." or $file3 eq ".."; $next4 = "$files3/$file4"; push(@files4, $next4); push(@all_files, $next4); } } $all_del = join("+", @all_files); print "<BR><HR><FONT COLOR=RED><B>Found Files & Directories</B></FONT><BR>"; foreach $all_files(@all_files) { print "$all_files<br>"; } print "<BR><HR><FONT COLOR=RED><B>Delete Files & Directories</B></FONT><BR>"; foreach $all_files(@all_files) { rmtree($all_files, 1, 1) or print " ! can't remove $all_files: $!<BR>"; #print "<BR>"; } print "<BR><HR><FONT COLOR=RED><B>Delete Forum Directory</B></FONT><BR>"; chdir($ForumsPath); rmdir($dir) or print "can't remove $dir: $!<BR><BR>"; } } print " $!<br>"; print "Whoa big mama."; exit; } It's spaghetti code, but good enough for a rough draft. ;-) I'll optimize it later.
|