emulating du with os.walk

Kirk Job-Sluder kirk at eyegor.jobsluder.net
Mon Sep 27 01:13:34 CEST 2004


Hrm, I'm a bit stumped on this.

I want to write a script lists a file directory hierarchy and gives me a
sorted list showing cumulative directory size.  The example code for 
os.walk gets me half-way there, but I can't quite figure out how to do
the hierarchal sum.  Here is the output I'm getting:

/home/kirk/.gconf/apps/ggv/layout consumes 228 bytes in 1 non-directory
files
/home/kirk/.gconf/apps/ggv consumes 0 bytes in 1 non-directory files
/home/kirk/.gconf/apps consumes 0 bytes in 1 non-directory files

However, what I want is:

/home/kirk/.gconf/apps/ggv/layout consumes 228 bytes in 1 non-directory
files 
/home/kirk/.gconf/apps/ggv consumes 228 bytes in 1 non-directory files
/home/kirk/.gconf/apps consumes 228 bytes in 1 non-directory files

There should be an easy way to get around this, or perhaps I'm better
off just parsing the output of du.

-- 
Kirk Job-Sluder
"The square-jawed homunculi of Tommy Hilfinger ads make every day an
existential holocaust."  --Scary Go Round



More information about the Python-list mailing list