Função que converte tamanhos de arquivos em um formato legível para humanos. Não lembro onde achei, se alguém souber o link para o site original por favor me avise.
Update: Enquanto limpava os bookmarks achei o site em que encontrei o código

?View Code PYTHON
#!/usr/bin/python
import os
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
 
if __name__ == "__main__":
    lista = os.listdir('.')
    for file in lista:
        print "File: %s Size: %s" % ((file),(sizeof_fmt(os.path.getsize(file))))

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word