if ( -e "path/to/file" ) {
print "File exists, hooray!";
}
else {
print "I couldn't find the file. Hohum:(";
}
kelan
Perl6 Grammar Student | [reply] [d/l] |
I hope not. I don't want your CGIs, nor your JavaScript to be able to see what do or don't I have on my disk.
"Link to a batch file on the user's computer" sounds suspicious enough by itself. What are you trying to do???
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature | [reply] |
I'm with jenda. What kind of hat is this question wearing? Page implies a website, so no, a website should not be able to see a file on my computer, unless I'm running my own local webserver. Please explain.
--
Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.
M-J D
| [reply] |
For checking of file existing you can use -e
(see perldoc -f -e and you will know all about working with file system in Perl):
if(-e $fname) { print 'File exists!' }
else { print 'File not found' }
in your script or in the module.
Also you can use module File::Find or File::Find::Rule
--------------------------------
SV* sv_bless(SV* sv, HV* stash);
| [reply] [d/l] [select] |
I would suggest File::Find, readdir, or failing on a function such as open.
To explain a little:
If you use readdir, you could get a list of all the files and do a regex match to see if the file your looking for exists. If not, redirect the user...as you suggested.
You could even do something like:
#pseudo code
open(FILE,"filename") ||
call_function_that_redirects_user_as_you_suggested.
#end pseudo code
HTH,
Chris | [reply] [d/l] |