diff options
author | Peng Wu <alexepico@gmail.com> | 2013-01-16 12:42:52 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2013-01-16 12:42:52 +0800 |
commit | 1a6fb6cc5eabf5774738885c4558c519371a67a8 (patch) | |
tree | 1f50e5e3a07c6a2d5046a6b45ca11a077afeeb6c /lib | |
parent | 4e36f08dce2034fcf9a813313c1653e5ae725e58 (diff) | |
download | trainer-1a6fb6cc5eabf5774738885c4558c519371a67a8.tar.gz trainer-1a6fb6cc5eabf5774738885c4558c519371a67a8.tar.xz trainer-1a6fb6cc5eabf5774738885c4558c519371a67a8.zip |
write dirwalk.py
Diffstat (limited to 'lib')
-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) |