Created
January 31, 2018 18:22
-
-
Save igorzakhar/1773a83723bb2aafd94562f055a1cf9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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