[Tutor] Sum files' size

Susana Iraiis Delgado Rodriguez susana.delgado_s at utzmg.edu.mx
Fri Jul 29 19:27:05 CEST 2011


Thank you to all of you!

After I read your mails I started to modify my code, I applied Ramit
suggestion and got the result I wanted:

mport 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'


#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
            s = os.path.getsize(filepath)
            shx1 = os.path.getsize(shx)
            p1 = s = os.path.getsize(p)
total = sizeof_fmt(s+shx1+p1)



2011/7/28 Prasad, Ramit <ramit.prasad at jpmchase.com>

> >kb = sizeof_fmt(s)
> >shx1 = os.path.getsize(shx)
> >kb2 = sizeof_fmt(shx1)
> > total = kb+kb2+kb3
>
> Instead only retrieve the formatted output at the end. That way you will
> not have to worry about converting back from strings, nor have to worry
> about adding number with different units (e.g. 10KB + 10MB).
>
> kb = s
> kb2 = os.path.getsize(shx)
> total = sizeof_fmt(kb+kb2+kb3)
>
> Ramit
>
>
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
>
>
>
> This communication is for informational purposes only. It is not
> intended as an offer or solicitation for the purchase or sale of
> any financial instrument or as an official confirmation of any
> transaction. All market prices, data and other information are not
> warranted as to completeness or accuracy and are subject to change
> without notice. Any comments or statements made herein do not
> necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
> and affiliates.
>
> This transmission may contain information that is privileged,
> confidential, legally privileged, and/or exempt from disclosure
> under applicable law. If you are not the intended recipient, you
> are hereby notified that any disclosure, copying, distribution, or
> use of the information contained herein (including any reliance
> thereon) is STRICTLY PROHIBITED. Although this transmission and any
> attachments are believed to be free of any virus or other defect
> that might affect any computer system into which it is received and
> opened, it is the responsibility of the recipient to ensure that it
> is virus free and no responsibility is accepted by JPMorgan Chase &
> Co., its subsidiaries and affiliates, as applicable, for any loss
> or damage arising in any way from its use. If you received this
> transmission in error, please immediately contact the sender and
> destroy the material in its entirety, whether in electronic or hard
> copy format. Thank you.
>
> Please refer to http://www.jpmorgan.com/pages/disclosures for
> disclosures relating to European legal entities.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110729/3b813300/attachment.html>


More information about the Tutor mailing list