From 1016b276ea8f88185e0013899bd31bafc1f0a239 Mon Sep 17 00:00:00 2001 From: Lucas Schumacher Date: Tue, 21 Nov 2023 10:37:10 -0500 Subject: [PATCH] first commit --- README.md | 2 ++ fs_ext.py | 17 +++++++++++++++++ fs_walk.py | 10 ++++++++++ 3 files changed, 29 insertions(+) create mode 100644 README.md create mode 100644 fs_ext.py create mode 100644 fs_walk.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..978c3ce --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# fs-py +Code snipits for iterating through the file system using python diff --git a/fs_ext.py b/fs_ext.py new file mode 100644 index 0000000..df75193 --- /dev/null +++ b/fs_ext.py @@ -0,0 +1,17 @@ +import os + +def walkPath(root): + extensions = {} + for root, dirs, files in os.walk(root): + for file in files: + ext = os.path.splitext(file)[1] + try: + extensions[ext] += 1 + except KeyError: + extensions[ext] = 1 + sortedExts = sorted(extensions.items(), key=lambda x: x[1]) + for ext, count in reversed(sortedExts): + print(ext, '\t\t', count) + +if __name__ == "__main__": + walkPath(os.getcwd()) diff --git a/fs_walk.py b/fs_walk.py new file mode 100644 index 0000000..074c57d --- /dev/null +++ b/fs_walk.py @@ -0,0 +1,10 @@ +import os + +def walkPath(root): + for root, dirs, files in os.walk(root): + print(root) + print("\tdirs:", dirs) + print("\tfiles:", files) + +if __name__ == "__main__": + walkPath(os.getcwd())