在使用os.path.getsize()和os.path.isfile時,我的腳本也返回了.DS_Store文件,這也是我不需要的。我如何忽略這些?如何忽略python函數中的隱藏文件?
import os
root = "/Users/Siddhartha/Desktop/py scripts"
for item in os.listdir(root):
if os.path.isfile(os.path.join(root, item)):
print item
'item.startswith( 「」)'? – 2013-03-05 23:02:59
您是否試圖忽略只有'.DS_Store',Finder認爲「隱藏」的任何內容,Finder認爲「隱藏」的任何內容或其在每個平臺上的相應內容,......? – abarnert 2013-03-05 23:09:07
或者,也許它是http://stackoverflow.com/questions/284115/cross-platform-hidden-file-detection/6365265#6365265的一個替代,取決於這個問題的答案。 – abarnert 2013-03-05 23:11:41