您好,如何忽略 .snapshot 之类的目录

Hello, how does one ignore a directory like .snaptshot

在 Python 中使用 os.walk 时如何忽略 .snapshot.git 之类的目录?

你能帮帮我吗?

这是我的代码:

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()

如何检查路径中的“.snapshot”或“.git”,如果找到 continue

...
for path, dirs, files in os.walk(datasource):
    if '.snapshot' in path or '.git' in path:
        continue
...