Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Reading from a deleted file is futile

by dynamo (Chaplain)
on Feb 12, 2008 at 12:52 UTC ( [id://667552] : note . print w/replies, xml ) Need Help??

in reply to Reading from a deleted file is futile

To determine whether a file is deleted or not (i.e., as jrtayloriv pointed out, whether there is an entry for it in it's directory), I feel compelled to offer yet another possible solution.

When I want to know if a file has been deleted or not (in a unix-like system,) I run ls, to list the directory's contents. If the entry has been removed, the file should be missing.. so this is one option (somewhat simplified):

$filename = "openfile.yaml"; $directory = "/over/here/somewhere/i/think/"; $fileIsDeleted = (`ls $directory` !~ /$filename/gs); print "Your file has ".($fileIsDeleted ? "" : "not ")."been deleted.";
This code has not been tested, but looks ok to me. It's really about the idea behind it anyway.