How To Do It Faster?!?
Laszlo Zsolt Nagy
gandalf at geochemsource.com
Wed Mar 30 19:00:54 EST 2005
andrea.gavana at agip.it wrote:
>Hello NG,
>
> in my application, I use os.walk() to walk on a BIG directory. I need
>to retrieve the files, in each sub-directory, that are owned by a
>particular user. Noting that I am on Windows (2000 or XP), this is what I
>do:
>
>for root, dirs, files in os.walk(MyBIGDirectory):
>
> a = os.popen("dir /q /-c /a-d " + root).read().split()
>
>
>
....
>Does anyone know if there is a faster way to do this job?
>
>
You can use the stat module to get attributes like last modification
date, uid, gid etc. The documentation of the stat module has a nice
example. Probably it will be faster because you are running an external
program (well, "dir" may be resident but still the OS needs to create a
new shell and interpret the parameters on every invocation).
If the speed is the same, you may still want to use the stat module because:
- it is platform independent
- it is independent of any external program (for example, the DIR
command can change in the future)
Best,
Laci
--
_________________________________________________________________
Laszlo Nagy web: http://designasign.biz
IT Consultant mail: gandalf at geochemsource.com
Python forever!
More information about the Python-list
mailing list