first commit
This commit is contained in:
commit
1016b276ea
2
README.md
Normal file
2
README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# fs-py
|
||||
Code snipits for iterating through the file system using python
|
||||
17
fs_ext.py
Normal file
17
fs_ext.py
Normal 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
10
fs_walk.py
Normal 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())
|
||||
Loading…
x
Reference in New Issue
Block a user