windows (python) os.path.exists os.path.isfile 是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4565619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
(python) os.path.exists os.path.isfile lies?
提问by eugene
os.path.exists is giving me incorrect answers.
os.path.exists 给了我不正确的答案。
it's not the same problem discussed at below link since I'm at windows. Are there other reasons for it to fail?
由于我在 windows 上,这与下面链接中讨论的问题不同。是否有其他原因导致它失败?
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..
当我针对 *.py 脚本运行的同一目录中的文件对其进行测试时,测试返回 ok,但没有任何子目录..
-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.
我正在查看该脚本运行时的子目录之一,并且可以从字面上看到文件的上次修改时间字段在 Windows 资源管理器中被更改。
我能想到我的计算机上没有其他东西会修改有问题的文件。
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
回答by Imran
os.path.exists
and os.path.isfile
is not case sensitive in Windows machines.
os.path.exists
并且os.path.isfile
在 Windows 机器中不区分大小写。
Here's what I get in Windows 7 (Python 2.7)
这是我在 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
回答by eugene
Turned out, os.path.exists and os.path.isfile is case-sensitive..
原来, os.path.exists 和 os.path.isfile 是区分大小写的..
Blah!
废话!