Re: Testing File Existence - best way?
am 27.12.2007 16:57:03 von Juha Laiho"Jürgen Exner"
>still just me wrote:
>> I need to test if a file exists. Is there a better technique than
>> "attempt open and watch for an error"? The program will be a cgi
>> running in a windows or linux environment.
>
>Why not use the "file exists" operator? See
>
> perldoc -f -e
Commenting on an old thread here, but it depends on what the OP wants to
do with the file. Separate tests for file access permissions/file existence
may create possibilities for race conditions (if there's a possibility
that an existing file gets its permissions modified/gets removed
between the test and actual desired operation).
So, for most cases attempt to operate on the file in the desired way
(and handling arising error conditions) is the best test.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)