Scanning through Directory

Michael Peuser mpeuser at web.de
Tue Aug 12 08:12:32 EDT 2003


There is a portable way of reading directories
   os.listdir
in conjunction with
  os.stat and a little help from os.path.split and os.path.join
Though using os.stat gives programs a somewhat clumbsy look,
I had not been too annoyed with it until I tried to scan a whole disk.
Reworking the join and split operations already gave a considerable
speed-up

As I need it for Windows I then with very little effort changed to:
   win32api.FindFiles
(I already had used win32api.GetDiskFreeSpace)

This was a breakthrough: 5 secs instead of 50+ !

os.listdir seems to do little more than win32api FindFiles
How can it be so slow???
Why is there no portable way of getting "DiskFreeSpace" info
Questions and Questions....

I strongly recommend the win32api calls it you have similar applications.
The interface is extremely simple and the only penalty is non-compatibility
;-)

I also recommend to use the Python profiler from time to time for programms
running more than one second. It might give you interesting insights...

Kindly
Michael Peuser










More information about the Python-list mailing list