get output of du / ls command - currently ugly code ...
ebonak at hotmail.com
Thu Aug 13 22:13:51 CEST 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.split())
>> print 'dir size: ', dir_size
> 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,
More information about the Python-list