[Tutor] Sum files' size
Susana Iraiis Delgado Rodriguez
susana.delgado_s at utzmg.edu.mx
Thu Jul 28 19:23:29 CEST 2011
I want to get the size of 3 files. I already completed this step. Then I
need to sum the 3 results I got. In order to do it I have the next code:
import os
file_list = []
folders = None
for root, folders, files in os.walk('C:\\'):
file_list.extend(os.path.join(root,fi) for fi in files if
(fi.endswith.shp))
for row, filepath in enumerate(file_list, start=1):
n = os.path.splitext(filepath)
p = n[0]+'.prj'
shx = n[0]+'.shx'
s = os.path.getsize(filepath)
#Function to get size in humam readable terms:
def sizeof_fmt(num):
for x in ['bytes','KB','MB','GB','TB']:
if num < 1024.0:
return "%3.1f%s" % (num, x)
num /= 1024.0
kb = sizeof_fmt(s)
shx1 = os.path.getsize(shx)
kb2 = sizeof_fmt(shx1)
#Finally I want to sum the 3 terms:
total = kb+kb2+kb3
But the output I got is : 15.5KB108.0bytes169.0bytes
Does anyone have an idea how to fix it?
Thank you!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110728/a9dde906/attachment-0001.html>
More information about the Tutor
mailing list