os.path.exists is giving me incorrect answers.
it's not the same problem discussed at below link since I'm at windows. Are there other reasons for it to fail?
os.path.exists() lies
The test returns ok when I test it against a file at the same directory as the *.py script runs, but none of its sub directories..
-EDIT-
I'm using absolute path.
I'm looking at one of the sub directories as this script runs, and can literally see file's last modified time field being changed in the windows explorer.
There are no other stuff going on my computer I can think of that will modify the files in question.def SaveIfNewer(doc, aiFile, pngFile):
options = win32com.client.Dispatch('Illustrator.ExportOptionsPNG24')
options.SetArtBoardClipping(True)
if (os.path.exists(pngFile)):
aiFileTime = os.stat(aiFile)[8]
pngFileTime = os.stat(pngFile)[8]
print("aiFileTime: ", aiFileTime, "pngFileTime: ", pngFileTime)
if(aiFileTime > pngFileTime):
os.remove(pngFile)
if( not os.开发者_开发百科path.isfile(pngFile)):
doc.Export(pngFile, constants.aiPNG24, options)
print 'exporting:', pngFile
else:
print 'skipping file:', pngFile
os.path.exists
and os.path.isfile
is not case sensitive in Windows machines.
Here's what I get in Windows 7 (Python 2.7)
>>> os.path.exists('C:/.rnd')
True
>>> os.path.exists('C:/.RND')
True
>>> os.path.isfile('C:/.rnd')
True
>>> os.path.isfile('C:/.RND')
True
Turned out, os.path.exists and os.path.isfile is case-sensitive..
Blah!
精彩评论