commit 1016b276ea8f88185e0013899bd31bafc1f0a239 Author: Lucas Schumacher Date: Tue Nov 21 10:37:10 2023 -0500 first commit 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())