473,511 Members | 16,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fast listdir & stat

I want to get the files and sizes and times etc. stats of a dir fast.
os.listdir & iterating with os.stat seems not to run at optimal speed for network folders. Is there a faster possibility? (both for Win & *nix ; best platform independent)
Robert
Nov 24 '06 #1
2 2656

robert wrote:
I want to get the files and sizes and times etc. stats of a dir fast.
os.listdir & iterating with os.stat seems not to run at optimal speed for network folders. Is there a faster possibility? (both for Win & *nix ; best platform independent)
Robert
An alternative is to work with os.walk() it returns a generator - see
http://docs.python.org/lib/lib.html, and os.path.getsize(),
os.path.gettmtime() - see http://docs.python.org/lib/module-os.path.html

Nov 24 '06 #2
wi******@hotmail.com wrote:
robert wrote:
>I want to get the files and sizes and times etc. stats of a dir fast.
os.listdir & iterating with os.stat seems not to run at optimal speed for network folders. Is there a faster possibility? (both for Win & *nix ; best platform independent)

An alternative is to work with os.walk() it returns a generator - see
http://docs.python.org/lib/lib.html, and os.path.getsize(),
os.path.gettmtime() - see http://docs.python.org/lib/module-os.path.html
would be even slower - 2 or 3 (network) calls for each file. os.walk just uses listdir.

Robert
Nov 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2971
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out...
4
3030
by: lebo | last post by:
Hi I'm trying to understand how Python handles memory usage and dynamic object loading and unloading. Problem to solve? Build a very low memory footprint (non-GUI) Python application for...
8
2436
by: Hannu Kankaanp?? | last post by:
This may be a bug or simply a strange result of undefined behaviour, but this is what I get with Python 2.3.2 on Windows XP: >>> import os >>> os.listdir('') >>> os.listdir(u'')
1
2780
by: rbt | last post by:
The below script produces a ' Bad File Descriptor' when executed. If I remove the try: except: statements, the script stops when the error occurs. The purpose of the script is to monitor the...
15
2562
by: Riccardo Galli | last post by:
Hi, I noticed that when I use os.listdir I need to work with absolute paths 90% of times. While I can use a for cycle, I'd prefere to use a list comprehension, but it becomes too long. I...
3
9507
by: Steven T. Hatton | last post by:
I found the following two statements in the file linked below: struct stat st; stat(fileName.c_str(), &st); http://websvn.kde.org/branches/work/kdevelop4-parser/main.cpp?rev=420247&view=markup...
1
3244
by: kai | last post by:
Hello, I use dircache.listdir(myDir) in my module repeatedly. On OS WIN 2000 listdir() will re-read the directory structure! But on AIX, listdir() will not re-read the directory structure (see...
2
1868
by: Plissken.s | last post by:
I have the following code which list out all the files/directories under the current directory. But how can I find out if 'f' is a directory? for f in os.listdir("."): // how can I check if...
3
5249
by: Magesh | last post by:
How date-time attributes of a file are represented in the structure "struct stat"? Coz as I noted they found to be unsigned integers and I donno how they are interpreted as date & time in the...
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.