Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- def get_size(start_path = '.'):
- total_size = 0
- for dirpath, dirnames, filenames in os.walk(start_path):
- for f in filenames:
- fp = os.path.join(dirpath, f)
- total_size += os.path.getsize(fp)
- if total_size == 0 and os.path.isfile(start_path):
- total_size += os.path.getsize(start_path)
- return total_size
- def listContents(start_path = '.'):
- print('running on dir "' + start_path + '"')
- dirName = os.path.basename(os.path.abspath(start_path))
- contents = os.listdir(start_path)
- f = open('output_' + dirName + '.csv', 'w')
- for c in contents:
- str(c.encode('utf8'))
- f.write(', ')
- f.write(str(get_size(start_path + '/' + c) / 1024 / 1024/ 1024) + '\n')
- f.close();
- if len(sys.argv) > 1:
- listContents(sys.argv[1])
- else:
- listContents();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement