1 2 3 4 5 6 7 8 9 10
use File::Path qw(remove_tree); chdir("$MEDIA_DIR"); # absoluter Pfad opendir(DIR, ".") || die $!; @entries = readdir(DIR); closedir(DIR); foreach (@entries) { # Hier habe ich die "."-Ordner "vergessen" remove_tree("$_") unless defined $media{"_$_"}; }
@entries = readdir(DIR);
Quoteremove_tree( $dir1, $dir2, ...., \%opts )
(...)
The following keys are recognised in the option hash:keep_root => $bool
When set to a true value, will cause all files and subdirectories to be removed, except the initially specified directories. This comes in handy when cleaning out an application's scratch directory.
remove_tree( '/tmp', {keep_root => 1} );
Quoteremove_tree( '/tmp', {keep_root => 1} );
remove_tree('/');