在Python中使用.snapshot
时,如何忽略.git
或os.walk
这样的目录?
你能帮助我吗?
这是我的代码:
datasource = "/home/me/PYTHON/OGL_TOOLS"
def scanfolder():
for path, dirs, files in os.walk(datasource):
depth = path.count('/') - 6
maxdepth = 2
if re.match ('^\S+.snapshot$', path) in dirs:
print ('bad format')
dirs.remove('.snapshot')
elif depth <= maxdepth:
for f in files:
#print (f)
if f.endswith('.txt'):
print (os.path.join(path, f))
filelog.write('\t{} => bonne syntaxe\n'.format(os.path.join(path, f)))
scanfolder()
答案 0 :(得分:0)
如何查看&#39; .snapshot&#39;或者&#39; .git&#39;在一个路径和continue
如果找到?
...
for path, dirs, files in os.walk(datasource):
if '.snapshot' in path or '.git' in path:
continue
...