
japhy
Enthusiast
Sep 5, 2000, 10:49 PM
Post #2 of 2
(105 views)
|
If the directory has OTHER directories in it, then you need to use a recursive approach, like the standard File::Path module: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> use File::Path 'rmtree'; rmtree $path; </pre><HR></BLOCKQUOTE> If it's just a directory with files, you can delete the files and then the directory: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> opendir DIR, $path or die "can't open $path: $!"; while (defined($file = readdir DIR)) { unlink "$path/$file" or warn "can't delete $path/$file: $!"; } closedir DIR; rmdir $path or warn "can't remove $path: $!"; </pre><HR></BLOCKQUOTE> ------------------ Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher
|