March 24th, 2013, 08:07 PM
Join Date: Mar 2013
Time spent in forums: 26 m 10 sec
Reputation Power: 0
Verify if file exist
I am new to this forum and I am new to python programming.
I have to write a python program which :
- read the path and the file to verify from a parameter. Input file to be verified could be on an external drive, a USB key, a SDHC card, a SAN (storage Area Network).
- have to verify if a given files exist or not
- if the file does not exist the program is to finish with an error number equal -99. This error is to be trapped by another program. For example, in applescript I would like to do on error.
At this moment, I've written the following line of code. For some reason the program says that the file does not exist when it does. I am not getting the path and the filename being passed by a parameter. I am keeping it simple.
I am using a MacBook Pro for writing the program.
from os import path
PATH = "Macintosh HD/IMG_3859.JPG"
if path.exists(PATH) and path.isfile(PATH):
print "File does exist"
print "File doesn't exist!", PATH
Thanks for your help!