Skip to content

Instantly share code, notes, and snippets.

@iSimar
Created February 15, 2016 17:26
Show Gist options
  • Select an option

  • Save iSimar/8c7c61b6485b0b1b0d4f to your computer and use it in GitHub Desktop.

Select an option

Save iSimar/8c7c61b6485b0b1b0d4f to your computer and use it in GitHub Desktop.
import os, os.path
import datetime
import csv
cur_dir=os.path.dirname(os.path.realpath(__file__))
timestamp=datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
def sizeof_fmt(num, suffix='B'):
for unit in ['','K','M','G','T']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)
with open('files_'+timestamp+'.csv', 'wb') as csvfile:
csv_writer=csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
for root, _, files in os.walk(cur_dir):
for f in files:
fullpath = os.path.join(root, f)
base_name = os.path.basename(fullpath)
dir_name = os.path.basename(os.path.normpath(fullpath))
file_size = os.path.getsize(fullpath)
csv_writer.writerow([dir_name, base_name, sizeof_fmt(int(file_size))])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment