Created
January 24, 2017 08:38
-
-
Save hoanbka/95c80c4b1b87d47624859a1f36281e3c to your computer and use it in GitHub Desktop.
Calculate the size of the folder using Python
This file contains hidden or 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 | |
res = [] | |
def readFolder(file): | |
if os.path.isfile(file): | |
res.append(os.path.getsize(file)) | |
else: | |
arr = os.listdir(file) | |
for element in arr: | |
child = file + "\\" + element | |
if os.path.isfile(child): | |
res.append(os.path.getsize(child)) | |
else: | |
readFolder(child) | |
return sum(res) | |
# path = 'D:\English\English_Collocations_in_Use_Advanced.pdf' | |
# path = 'D:\English\CDIeltsband5.5-6.5.rar' | |
path = 'D:\English' | |
# print(readFolder(path)) | |
arr = readFolder(path) | |
print(arr) | |
# print(os.path.isfile("D:\English\TOEIC\900A\Test10 - Tu luyen TOEIC 900.mp3")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment