Skip to content

Instantly share code, notes, and snippets.

@igorzakhar
Created January 31, 2018 18:22
Show Gist options
  • Save igorzakhar/1773a83723bb2aafd94562f055a1cf9a to your computer and use it in GitHub Desktop.
Save igorzakhar/1773a83723bb2aafd94562f055a1cf9a to your computer and use it in GitHub Desktop.
import os
def convert_bytes(num):
for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
if num < 1024.0:
return "%3.1f %s" % (num, x)
num /= 1024.0
def file_size(file_path):
if os.path.isfile(file_path):
file_info = os.stat(file_path)
return convert_bytes(file_info.st_size)
if __name__ == '__main__':
files_path = "js"
list_of_files = os.listdir(files_path)
for file in list_of_files:
path = '{}/{}'.format(files_path, file)
size = file_size(path)
print('{:17}:{}'.format(file, size))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment