Add 'fileextensionstats.py'
This commit is contained in:
16
fileextensionstats.py
Normal file
16
fileextensionstats.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import os
|
||||||
|
from collections import defaultdict
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
"""
|
||||||
|
Display the total file size of files in a directory and subdirectories,
|
||||||
|
grouped by extension.
|
||||||
|
"""
|
||||||
|
|
||||||
|
stats = defaultdict(int)
|
||||||
|
for (dirpath, _, filenames) in os.walk(r"/put/some/path/here"):
|
||||||
|
for filename in filenames:
|
||||||
|
_, extension = os.path.splitext(filename)
|
||||||
|
stats[extension] += os.path.getsize(os.path.join(dirpath, filename))
|
||||||
|
|
||||||
|
pprint(stats)
|
Reference in New Issue
Block a user