Skip navigation.
Home
Your source for Perl tips, howto's, faq and tutorials
( categories: )

Use the rmtree function provided by File::Path module:

use File::Path;
 
#-- remove all the tree in quiet mode
$files_deleted = rmtree('/tmp/test');
 
print "Number of files deleted in /tmp/test: $files_deleted\n";
 
#-- remove all the tree in verbose mode
$files_deleted = rmtree('/tmp/old_files', 1);
 
print "Number of files deleted in /tmp/old_files: $files_deleted\n";

NOTE:
- Symbolic links are simply deleted and not followed