Hello,
I have been trying a number of ways to determine whether a file exists in a particular
directory, but to no avail.
The perl books I have (and many web sites/forums I have checked) mention the '-e' test
on a filehandle or filename, but it returns false (the file does not exist) even if it
does. I have used code such as:
if (-e 'filepath/filename') { # using absolute naming with full pathname etc.
# display the file (image) in the HTML output
}
and
if (-e "$filepath/$filename") { # using variables as the path and name information
# display the file
}
and
if (open(TMP, "<$filepath/$filename")) { # to test whether the file can be opened
# I would expect a false (or undef) if the file did not exist
# display the file
}
I commented out the if statement (and closing brace '}' ), and manually set the file
to be displayed, and it worked. That was to check that the path & filename were
correct. I would like to be able to display the image if it exists, or display
another 'image does not exist' image if the image file does not exist.
I have even tried the 'use File::stat' module methods.
I do not get any fatal errors - the rest of the HTML output works fine - just no image
displayed even though I know the filepath & name do indeed exist. Am I missing
something obvious? The only thing I can think of at this stage is that the -e test
(and related file tests) are for Unix-based servers and I am running from a MS
IIS-based server. But if that were the case, wouldn't the server spit out an error
that it didn't understand -e? Are there similar (but different) file tests for IIS?
Thanks in advance,
Mike.