PYTHONBREAKPOINT = 0 #disallow breakpoints import pdb import re import os import sys import platform import inspect import os.path #Globals HTTPHEADER = 'https://www.lutemusic.org/' currOS = platform.platform() if currOS.find('Windows') == 0: #LOCALBASE = 'C:/website/' LOCALBASE = 'A:/website/' else: LOCALBASE = '/ssd/home/sarge/prog/python/fron/' CURRDIR = re.sub('\\\\+', '/', os.getcwd()) + '/' FACHEAD = LOCALBASE + "facsimiles/" def join_with_fslash(s1, s2): return(s1 + '/' + s2) # end join_with_fslash # Walk the main directory tree: def walk_tree(sDir): count = 0 # of image directories processed. sDir = sDir.replace("\\", '/') oldDir = "" for root, dirs, files in os.walk(sDir): #Only when changing root directories do we collect a list of image files root = root.replace("\\", '/') if root == oldDir: continue # Now we have a new "old directory" oldDir = root # Get a list of image files in this directory images = [f for f in files if f.endswith('.png')] if len(images) == 0: continue indexfile = root + '/' + 'dir.inx' # open file to write image array to finx = open(indexfile, 'w') for i in range(len(images)): line_out = HTTPHEADER + root.replace(LOCALBASE, '') + '/' + images[i] + '\n' finx.write(line_out) finx.close() count += 1 # Process each image file in the list. # end for fname in images # end if root != oldDir # After walking the directories. return count # end walk_tree def main(): count = walk_tree(FACHEAD) print('We have created ' + str(count) + ' image indices.\n') # end main if __name__ == "__main__": main()