from __future__ import print_function import os import glob def sortAscAsInt (aList): return sorted([f for f in aList if filterNames(f)], key=int) def filterNames (name): try: int(name) return True except: return False def filesFromFolder (path, foldername): try: fullPath = os.path.join(path, foldername) contentList = os.listdir(fullPath) return [s for s in sortAscAsInt(contentList) if os.path.isdir(os.path.join(fullPath, s))] except: print("Directory %s not found at %s." % (foldername, path)) return [] def countFolders (path, foldername = ""): files = filesFromFolder(path, foldername) return len(files) def highestFileName (path, foldername = ""): files = filesFromFolder(path, foldername) return max(files, key=int) def getFilesInFolder (folder, pattern): return glob.glob(folder + "/" + pattern)