Scanning through Directory

M

Michael Peuser

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
 
A

Anand Pillai

Did you try os.path.walk() in your experiments?
If you did, you could post the profile data for it too.
I find it one of the most useful functions defined in
the os.path module.

Thanks!

Anand
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top