dosya/dizin boyutunu hesaplamak zor iş :(.

This commit is contained in:
Barış Metin
2005-06-20 12:17:59 +00:00
parent fc6d5151de
commit cd498e08c4
+4 -1
View File
@@ -37,11 +37,14 @@ def clean_dir(top):
def dir_size(dir): def dir_size(dir):
""" calculate the size of files under a dir """ calculate the size of files under a dir
based on the os module example""" based on the os module example"""
# It's really hard to give an approximate value for package's
# installed size. Gettin a sum of all files' sizes if far from
# being true. Using 'du' command (like Debian does) can be a
# better solution :(.
getsize = os.path.getsize getsize = os.path.getsize
join = os.path.join join = os.path.join
def sizes(): def sizes():
for root, dirs, files in os.walk(dir): for root, dirs, files in os.walk(dir):
print sum([getsize(join(root, name)) for name in files])
yield sum([getsize(join(root, name)) for name in files]) yield sum([getsize(join(root, name)) for name in files])
return sum( sizes() ) return sum( sizes() )