9.2. Deleting a FileProblem
You want to delete a file. Perl's Solution
Use Perl's standard unlink($FILENAME) or die "Can't delete $FILENAME: $!\n"; unlink(@FILENAMES) == @FILENAMES or die "Couldn't unlink all of @FILENAMES: $!\n"; Discussion
The unlink($file) or die "Can't unlink $file: $!";
unless (($count = unlink(@filelist)) == @filelist) { warn "could only delete $count of " . (@filelist) . " files"; }
A Under Unix, deleting a file from a directory requires write access to the directory,[ 1 ] not to the file, because it's the directory you're changing. Under some circumstances, you could remove a file you couldn't write to or write to a file you couldn't remove.
If you delete a file that some process still has open, the operating system removes the directory entry but doesn't free up data blocks until all processes have closed the file. This is how the See Also
The Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|