Recursive file tree add thing
Published: Wednesday, Dec 26, 2007 Last modified: Wednesday, Oct 2, 2024
Looks something like:
#!/usr/bin/env python2
import re
import os
import sys
def add_dir(dir):
filenames = os.listdir(dir)
filenames.sort()
subdirs = []
for filename in filenames:
pathname = os.path.join(dir, filename)
if VALID_PICTURE(filename):
print pathname
if os.path.isdir(pathname):
subdirs.append(pathname)
map(add_dir, subdirs)
def VALID_PICTURE(name):
if re.search("\.(png|jpg)$", name, re.I):
return 1
if __name__ == '__main__':
patharg = sys.argv[1]
print "Adding", patharg
add_dir(patharg)