M626
Programmer
- Mar 13, 2002
- 299
What is the most efficent and simplest way to delete files from a directory. Control whats deleted by a text file that list files that can be deleted.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
open FH, "list_of_files.txt";
unlink <FH>;
close FH;
Don't unlink or rename an open file
unlink <*.txt>;
open FH, "list_of_files.txt";
unlink map { "/usr/home/brigmar/" . $_ } <FH>;
close FH;
open FH, "deletelist.dat";
while (<FH>) {
chomp;
print unlink "C:/Temp/$_" ? "File '$_' deleted\n" : File '$_' not deleted: $!\n";
}
close FH;