diff options
Diffstat (limited to 'lib/dirwalk.py')
-rw-r--r-- | lib/dirwalk.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/dirwalk.py b/lib/dirwalk.py new file mode 100644 index 0000000..e2ab090 --- /dev/null +++ b/lib/dirwalk.py @@ -0,0 +1,39 @@ +import os +from myconfig import MyConfig + + +config = MyConfig() + + +def handleError(error): + sys.exit(error) + + +def walkIndex(handleOneIndex, path): + for root, dirs, files in os.walk(path, topdown=True, onerror=handleError): + for onefile in files: + filepath = os.path.join(root, onefile) + indexpostfix = config.getIndexPostfix() + if onefile.endswith(indexpostfix): + subdir = os.path.relpath(root, path) + indexname = onefile[:-len(indexpostfix)] + handleOneIndex(filepath, subdir, indexname) + elif onefile.endswith(config.getStatusPostfix()): + pass + else: + print('Unexpected file:' + filepath) + + +def walkIndexFast(handleOneIndex, path, fast): + for root, dirs, files in os.walk(path, topdown=True, onerror=handleError): + for onefile in files: + filepath = os.path.join(root, onefile) + indexpostfix = config.getIndexPostfix() + if onefile.endswith(indexpostfix): + subdir = os.path.relpath(root, path) + indexname = onefile[:-len(indexpostfix)] + handleOneIndex(filepath, subdir, indexname, fast) + elif onefile.endswith(config.getStatusPostfix()): + pass + else: + print('Unexpected file:' + filepath) |