How does one ignore a directory like .snapshot
or .git
when using os.walk
in Python?
Can you help me?
Here is my code:
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()