[pygtk] howto get the directory size

Gustavo J. A. M. Carneiro gjc at inescporto.pt
Thu Jul 21 18:02:37 WST 2005


On Wed, 2005-07-20 at 13:45 +0300, Ogz wrote:
> With such a code: gnomevfs.async.get_file_info(uri),
> fileinfo_callback, options = gnomevfs.FILE_INFO_DEFAULT |
> gnomevfs.FILE_INFO_GET_MIME_TYPE)
> 
> ıt is possible to get the size of the file by using fileinfo_callback function. 
> 
> Is there a way like this for directories? When i apply it for a
> directory name, i get 4MB, fix size wich doesnt include the sub files
> or directories size.

  I'm afraid you have to count the directory size yourself.  You could
use gnomevfs.DirectoryHandle(uri, options), eg. (untested code):

def disk_usage(uri):
	size = 0
	for info in gnomevfs.DirectoryHandle(uri):
		size += info.size
		if info.type & gnomevfs.FILE_TYPE_DIRECTORY:
			size += disk_usage(uri.append_file_name(info.name)
	return size


> _______________________________________________
> pygtk mailing list   pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
-- 
Gustavo J. A. M. Carneiro
<gjc at inescporto.pt> <gustavo at users.sourceforge.net>
The universe is always one step beyond logic



More information about the pygtk mailing list