get output of du / ls command - currently ugly code ...
ebonak at hotmail.com
Thu Aug 13 21:28:44 CEST 2009
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.
The code I have seems hideous, but it seems to work. Surely there is an
easier,more elegant way to do this?
dir_size = os.popen('du -sk somename')
data = dir_size.readlines()
dir_size = int(data.split())
print 'dir size: ', dir_size
tar_size = os.popen('ls -s somename.tar.gz')
data = tar_size.readlines()
tar_size = int(data.split())
print 'tar size: ', tar_size
More information about the Python-list