workdir = '/Volumes/place/sub place'
def myFunc(bla, dir, flist):
for f in flist:
print f, os.path.isfile(f)
os.path.walk(workdir,myFunc,None)
返回:
tests.py False
utils.py False
utils.pyc False
writeXmlForMpgInPath.py False
.DS_Store True
Playout False
Playout Masters False
Projects False
ProRes Masters False
Source False
Sydney Playout Masters False
Web Preview False
.AU009644-M.xml.swp False
.DS_Store True
.DS_Store True
.DS_Store True
.DS_Store True
答案 0 :(得分:4)
您正在使用错误的功能:
workdir = '/Volumes/place/sub place'
def myFunc(_, dir, flist):
for f in flist:
fpath = os.path.join(dir, f) # need to make a full path first
print f, fpath, os.path.isfile(fpath)
os.path.walk(workdir,myFunc,None)
另见os.walk
,更好。