get output of du / ls command - currently ugly code ...

Esmail ebonak at hotmail.com
Thu Aug 13 16:13:51 EDT 2009


rebfj at yahoo.co.uk wrote:
> On Aug 13, 8:28 pm, Esmail <ebo... at hotmail.com> wrote:
>> Hi all,
>>
>> Essentially all I want to know the size of a directory, and the size
>> of a zipped tarball so that I can compute/report the compression ratio.
>>

>>      dir_size = os.popen('du -sk somename')
>>      data = dir_size.readlines()
>>      dir_size = int(data[0].split()[0])
>>      print 'dir size: ', dir_size
>>

Hi,

  > Try using os.path.getsize(somename.tar.gz)

Beautiful! .. that takes care of the tarball .. but it doesn't seem to
work for reporting the total size of the directory. Any suggestions how
to do that in a nicer way?

I just looked through os.path.* and there doesn't seem to be a function
to report what "du -sb" would.

Thanks for your help,

Esmail




More information about the Python-list mailing list