first commit

This commit is contained in:
Lucas Schumacher 2023-11-21 10:37:10 -05:00
commit 1016b276ea
3 changed files with 29 additions and 0 deletions

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# fs-py
Code snipits for iterating through the file system using python

17
fs_ext.py Normal file
View File

@ -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())

10
fs_walk.py Normal file
View File

@ -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())