我正试图在python中编写一个目录遍历器,它确定要找到一个文件类型。我的问题是,我可能会引用子文件夹中的父文件夹,从而产生一个循环。我有办法克服这个问题吗?我的代码是这样的:
def _hasMp3(path, fileTypes):
if path:
childDirs = [root]
fileTypes = fileTypes or []
while childDirs:
qdir = childDirs.pop()
path = unicode(qdir.absolutePath())
path = os.path.normalpath(path)
return False 发布于 2015-09-24 16:23:57
获取每个目录的解析路径,并保留前面看到的所有路径:
seen = set()
while subDirs:
qdir = subDirs.pop()
path = unicode(qdir.canonicalPath())
if path in seen:
continue
seen.add(path)https://stackoverflow.com/questions/32765927
复制相似问题