Re: scandir slower than listdir

2017-07-20 Thread Tim Delaney
On 20 July 2017 at 21:43, Skip Montanaro wrote: > scandir returns an iterator of DirEntry objects which contain more > > information than the mere name. > > > > As I recall, the motivation for scandir was to avoid subsequent system > calls, so it will be slower than listd

Re: scandir slower than listdir

2017-07-20 Thread Steve D'Aprano
On Thu, 20 Jul 2017 03:33 pm, Torsten Bronger wrote: > Hallöchen! > > With a 24,000 files directory on an SSD running Ubuntu, > > #!/usr/bin/python3 > > import os, time > > > start = time.time() > list(os.listdir("/home/bronger/.save

Re: scandir slower than listdir

2017-07-20 Thread Skip Montanaro
scandir returns an iterator of DirEntry objects which contain more > information than the mere name. > As I recall, the motivation for scandir was to avoid subsequent system calls, so it will be slower than listdir the way you've tested it. If you add in the cost of fetching the other

Re: scandir slower than listdir

2017-07-19 Thread Terry Reedy
On 7/20/2017 1:33 AM, Torsten Bronger wrote: Hallöchen! With a 24,000 files directory on an SSD running Ubuntu, #!/usr/bin/python3 import os, time start = time.time() list(os.listdir("/home/bronger/.saves")) listdir returns a list of na prin

scandir slower than listdir

2017-07-19 Thread Torsten Bronger
Hallöchen! With a 24,000 files directory on an SSD running Ubuntu, #!/usr/bin/python3 import os, time start = time.time() list(os.listdir("/home/bronger/.saves")) print("listdir:", time.time() - start) start = time.time() list(os.scandir(&

Re: listdir

2016-09-05 Thread breamoreboy
On Monday, September 5, 2016 at 4:34:45 PM UTC+1, Rustom Mody wrote: > So what do you get when you replace the if-else with a simple: print(file) ? > > [And BTW dont use the variable name “file” its um sacred] Only in Python 2, it's gone from the built-ins in Python 3 https://docs.python.org/3/

Re: listdir

2016-09-05 Thread Chris Angelico
On Tue, Sep 6, 2016 at 2:29 AM, Smith wrote: >> What exactly are you expecting the 'break' to do here? Can you explain >> to me the intent of your code? >> >> ChrisA >> > I'd like to create a script that searches the directory .py files. > If the script does not find the file extension .py would r

Re: listdir

2016-09-05 Thread Smith
What exactly are you expecting the 'break' to do here? Can you explain to me the intent of your code? ChrisA I'd like to create a script that searches the directory .py files. If the script does not find the file extension .py would return the error message "File Not Found". -- https://mai

Re: listdir

2016-09-05 Thread Smith
On 05/09/2016 17:57, jmp wrote: Is that what you're expecting ? A slightly different version: import glob, os a = input("search for files with the extension .py into directory: ") print glob.glob(os.path.join(a, '*.py')) jm Thank you Sorry, but i'm newbie :-( -- https://mail.python.org/ma

Re: listdir

2016-09-05 Thread jmp
On 09/05/2016 05:41 PM, Smith wrote: Il 05/09/2016 17:34, Rustom Mody ha scritto: So what do you get when you replace the if-else with a simple: print(file) a = input("search for files with the extension .py into directory: ") for file in os.listdir(a): if file.endswith(".py"):

Re: listdir

2016-09-05 Thread Smith
Il 05/09/2016 17:34, Rustom Mody ha scritto: So what do you get when you replace the if-else with a simple: print(file) a = input("search for files with the extension .py into directory: ") for file in os.listdir(a): if file.endswith(".py"): print(file) search for fil

Re: listdir

2016-09-05 Thread Chris Angelico
On Tue, Sep 6, 2016 at 1:27 AM, Smith wrote: > Hello to all, > I wanted to know because even though the files are present on the directory > I write input gives me "file not found". > You can help me? > Thank you > > a = input("Digita la directory dove vuoi trovare i file py: ") > for file in os.

Re: listdir

2016-09-05 Thread Chris Angelico
On Tue, Sep 6, 2016 at 1:34 AM, Rustom Mody wrote: > [And BTW dont use the variable name “file” its um sacred] Nah, that part's fine. Python isn't religious about builtins. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: listdir

2016-09-05 Thread Rustom Mody
So what do you get when you replace the if-else with a simple: print(file) ? [And BTW dont use the variable name “file” its um sacred] -- https://mail.python.org/mailman/listinfo/python-list

Re: listdir

2016-09-05 Thread jmp
On 09/05/2016 05:27 PM, Smith wrote: Hello to all, I wanted to know because even though the files are present on the directory I write input gives me "file not found". You can help me? Thank you a = input("Digita la directory dove vuoi trovare i file py: ") for file in os.listdir(a): if fi

Re: listdir

2016-09-05 Thread Smith
Il 05/09/2016 17:27, Smith ha scritto: Hello to all, I wanted to know because even though the files are present on the directory I write input gives me "file not found". You can help me? Thank you a = input("Digita la directory dove vuoi trovare i file py: ") for file in os.listdir(a): if f

listdir

2016-09-05 Thread Smith
Hello to all, I wanted to know because even though the files are present on the directory I write input gives me "file not found". You can help me? Thank you a = input("Digita la directory dove vuoi trovare i file py: ") for file in os.listdir(a): if file.endswith(".py"): print(fil

Re: Linux drives me crazy... Rights, listdir...

2011-03-29 Thread durumdara
Hi! Sorry. The path was wrong! "backup_redmine <> redmine_backup"... :-( Thanks: dd -- http://mail.python.org/mailman/listinfo/python-list

Linux drives me crazy... Rights, listdir...

2011-03-29 Thread durumdara
up on execution. Everything is same, but when I check os.listdir() on this dir, I see only two folders. 5 elements are here: Files_Zipped (dir) MySQL_Dump (dir) Log (dir) Log2 (dir) BackupRedmine.py (the script) The listdir show only: Files_Zipped MySQL_Dump (It don't see itself!) Because it don

RE: listdir reports [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid

2009-01-08 Thread Per Olav Kroka
FYI: the '/*.*' is part of the error message returned. -Original Message- From: ch...@rebertia.com [mailto:ch...@rebertia.com] On Behalf Of Chris Rebert Sent: Wednesday, January 07, 2009 6:40 PM To: Per Olav Kroka Cc: python-list@python.org Subject: Re: listdir reports [Error

Re: listdir reports [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid

2009-01-07 Thread Chris Rebert
> PS: Why does the listdir() function add '*.*' to the path? Don't know what you're talking about. It doesn't do any globbing or add "*.*" to the path. Its exclusive purpose is to list the contents of a directory, so /in a sense/ it does add "*.*

listdir reports [Error 1006] The volume for a file has been externally altered so that the opened file is no longer valid

2009-01-07 Thread PerOK
en some/all caches have forgot about the directory. If I query the directory again (multiple times) listdir() will finally return the content of the directory. The "DOS" command DIR has no problem listing the same directory. Configuration: >>> sys.version '2.5.4 (r254:67916, D

Re: problem with listdir

2008-04-27 Thread castironpi
#x27;Invalid switch - "*.*".' > > Probably because on the command-line, / means a command-line option. > Been a while since I used DOS. > > Try this instead: > > dir f:\code\python\pgmgallery\*.*" > > David. Try typing listdir( '.' ), which

Re: problem with listdir

2008-04-26 Thread David
On Sat, Apr 26, 2008 at 7:56 PM, jimgardener <[EMAIL PROTECTED]> wrote: > > > * Run cmd.exe and see if you can run "dir f:\\code\\python\pgmgallery/*.*" > > > > that causes a message 'Invalid switch - "*.*".' > > Probably because on the command-line, / means a command-line option. Been a while

Re: problem with listdir

2008-04-26 Thread jimgardener
> * Run cmd.exe and see if you can run "dir f:\\code\\python\pgmgallery/*.*" > that causes a message 'Invalid switch - "*.*".' > * Try using other directories under F: drive in your program and see> when > you start hitting the problem. i tried that..on some directories in the same drive this

Re: problem with listdir

2008-04-26 Thread Kam-Hung Soh
list of filenames using listdir pgmdir="f:\code\python\pgmgallery" # where i have pgm files g2=listdir(pgmdir) i get the following error WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'f:\\code\\python\pgmgallery/*.*' i am run

Re: problem with listdir

2008-04-26 Thread Francesco Bochicchio
On Sat, 26 Apr 2008 01:24:23 -0700, jimgardener wrote: > hi > i have a directory containing .pgm files of P5 type.i wanted to read > the pixel values of these files ,so as a firststep i wrote code to > make a list of filenames using listdir > > pgmdir="f:\code\python\pgm

Re: problem with listdir

2008-04-26 Thread David
> > i get the following error > WindowsError: [Error 123] The filename, directory name, or volume > label syntax is incorrect: 'f:\\code\\python\pgmgallery/*.*' > > i am running python on winXP ..can anyone tell me why i get this > error? > -- >From some Googling, it looks like this error ca

problem with listdir

2008-04-26 Thread jimgardener
hi i have a directory containing .pgm files of P5 type.i wanted to read the pixel values of these files ,so as a firststep i wrote code to make a list of filenames using listdir pgmdir="f:\code\python\pgmgallery" # where i have pgm files g2=listdir(pgmdir) i get the follo

Re: listdir() with mask

2007-12-14 Thread grflanagan
On Dec 14, 2:00 pm, "Vladimir Rusinov" <[EMAIL PROTECTED]> wrote: >Is there any easy way to list files using bash-like patterns? Something like >listfiles("/var/log/*.log"), listfiles("/var/{cache,run}/*"). > On 12/14/07, Jeff McNeil <[EMAIL PROTECTED]> wrote: > > > > > Sure is.. check out the glob

Re: listdir() with mask

2007-12-14 Thread Vladimir Rusinov
On 12/14/07, Jeff McNeil <[EMAIL PROTECTED]> wrote: > > Sure is.. check out the glob module: > http://www.python.org/doc/current/lib/module-glob.html (Official) > http://blog.doughellmann.com/2007/07/pymotw-glob.html (PyMOTW) > Thanks a lot! -- Vladimir Rusinov GreenMice Solutions: IT-решения на

Re: listdir() with mask

2007-12-14 Thread Rick Dooling
On Dec 14, 1:56 am, "Vladimir Rusinov" <[EMAIL PROTECTED]> wrote: glob or fnmatch http://docs.python.org/lib/module-glob.html rd -- http://mail.python.org/mailman/listinfo/python-list

Re: listdir() with mask

2007-12-14 Thread Jeff McNeil
Sure is.. check out the glob module: http://www.python.org/doc/current/lib/module-glob.html (Official) http://blog.doughellmann.com/2007/07/pymotw-glob.html (PyMOTW) Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type "help", "copyright", "cre

listdir() with mask

2007-12-14 Thread Vladimir Rusinov
Hello! Is there any easy way to list files using bash-like patterns? Something like listfiles("/var/log/*.log"), listfiles("/var/{cache,run}/*"). Also, I'll need something like listfiles("/tmp/**/*.tmp"), where ** is unlimited number of folders (like is zsh). Thanks and sorry for my English. --

Re: How can I check if the listdir result a directory?

2007-03-22 Thread Tim Daneliuk
[EMAIL PROTECTED] wrote: > 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 'f' a directory? > Try os.path.isdir() -- -

Re: How can I check if the listdir result a directory?

2007-03-22 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > for f in os.listdir("."): > // how can I check if 'f' a directory? Your two approaches are 1) use os.stat (or stat.stat) and check the mode bits; or 2) use os.listdir and catch the OSError exception you get if you use it on a non-directory. --

How can I check if the listdir result a directory?

2007-03-22 Thread [EMAIL PROTECTED]
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 'f' a directory? -- http://mail.python.org/mailman/listinfo/python-list

Re: fast listdir & stat

2006-11-24 Thread robert
or 3 (network) calls for each file. os.walk just uses listdir. Robert -- http://mail.python.org/mailman/listinfo/python-list

Re: fast listdir & stat

2006-11-24 Thread [EMAIL PROTECTED]
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

Re: os listdir access denied when run as a service

2006-05-26 Thread Ian Parker
In message <[EMAIL PROTECTED]>, Thomas Thomas <[EMAIL PROTECTED]> writes >Hi All, > >I am trying to access a mapped network drive folder. everything works fine >normally. But when i run the application as service I am getting the error > >Traceback (most recent call last): > File "docBoxApp.py",

Re: os listdir access denied when run as a service

2006-05-25 Thread Larry Bates
Thomas Thomas wrote: > Hi All, > > I am trying to access a mapped network drive folder. everything works fine > normally. But when i run the application as service I am getting the error > > Traceback (most recent call last): > File "docBoxApp.py", line 129, in ? > File "core\PollFiles.pyc",

Re: [Python-Help] os listdir access denied when run as a service

2006-05-25 Thread Danny Yoo
On Thu, 25 May 2006, Thomas Thomas wrote: > I am trying to access a mapped network drive folder. everything works > fine normally. But when i run the application as service I am getting > the error The error is on the line: for filename in os.listdir(folder):#line 25 and I have to ass

os listdir access denied when run as a service

2006-05-24 Thread Thomas Thomas
Hi All, I am trying to access a mapped network drive folder. everything works fine normally. But when i run the application as service I am getting the error Traceback (most recent call last): File "docBoxApp.py", line 129, in ? File "core\PollFiles.pyc", line 332, in doPoll File "core\Poll

Re: listdir() - any way to limit # of file entries?

2006-02-22 Thread Roger Upole
g. We have several programs > that have been dumping files into a folder (one folder) for some time now. I > want to limit the number of files returned by listdir to avoid trying to > build a > list with tons of entries. I then want to move those files into a zip archive > for the a

Re: listdir() - any way to limit # of file entries?

2006-02-22 Thread Larry Bates
Peter A. Schott wrote: > I want to build a program that does some archiving. We have several programs > that have been dumping files into a folder (one folder) for some time now. I > want to limit the number of files returned by listdir to avoid trying to > build a > list with

Re: listdir() - any way to limit # of file entries?

2006-02-22 Thread Paul Rubin
Peter A. Schott <[EMAIL PROTECTED]> writes: > Is there any way to build a list of the first 1000 files or so in a folder? The obvious way is first_1000 = os.listdir()[:1000] That does build a potentially bigger list in memory before chopping off the 1000 elements, but unless you're running ou

listdir() - any way to limit # of file entries?

2006-02-22 Thread Peter A.Schott
I want to build a program that does some archiving. We have several programs that have been dumping files into a folder (one folder) for some time now. I want to limit the number of files returned by listdir to avoid trying to build a list with tons of entries. I then want to move those files

Re: File list from listdir or shell?

2005-05-26 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Unluckily, to capture the stdout I have to redirect it to a file... > I hoped that this could work ... > lF=sys.stdin.readline(os.system("ls -1 *.py")) hint: look up "os.popen" and "subprocess" in the library reference. -- http://mail.python.org/mailman/listinfo/p

Re: File list from listdir or shell?

2005-05-26 Thread Thomas Guettler
Am Thu, 26 May 2005 06:31:40 -0700 schrieb qwweeeit: Hi, > ls -1 *.py (for the filenames only) or This can be done with the module "glob" of the standard library. HTH, Thomas -- Thomas Güttler, http://www.thomas-guettler.de/ -- http://mail.python.org/mailman/listinfo/python-list

File list from listdir or shell?

2005-05-26 Thread qwweeeit
Hi all, to obtain a file list from a dir you can use: import os, sys try: . sExtension=sys.argv[1] . sPath=sys.argv[2] except: . sExtension="" . sPath='.' lF=os.listdir(sPath) # to remove from the list also the names of backup files lF=filter(lambda lF: '~' not in lF and sExtension in lF,lF