Re: waling a directory with very many files

2009-06-21 Thread rkl
On Jun 15, 2:35 am, tom f...@thefsb.org wrote: i can traverse adirectoryusing os.listdir() or os.walk(). but if adirectoryhas a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an object by walking

Re: waling a directory with very many files

2009-06-21 Thread Tim Golden
rkl wrote: I might be a little late with my comment here. David Beazley in his PyCon'2008 presentation Generator Tricks For Systems Programmers had this very elegant example of handling an unlimited numbers of files: David Beazley's generator stuff is definitely worth recommending on. I

Re: waling a directory with very many files

2009-06-17 Thread Asun Friere
On Jun 15, 6:35 am, Andre Engels andreeng...@gmail.com wrote: What kind of directories are those that just a list of files would result in a very large object? I don't think I have ever seen directories with more than a few thousand files... (a...@lucrezia:~/pit/lsa/act:5)$ ls -1 | wc -l

Re: waling a directory with very many files

2009-06-16 Thread Hrvoje Niksic
Nick Craig-Wood n...@craig-wood.com writes: It can be done properly with gccxml though which converts structures into ctypes definitions. That sounds interesting. That said the dirent struct is specified by POSIX so if you get the correct types for all the individual members then it should

Re: waling a directory with very many files

2009-06-16 Thread thebjorn
On Jun 15, 6:56 am, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: On Sun, 14 Jun 2009 22:35:50 +0200, Andre Engels wrote: On Sun, Jun 14, 2009 at 6:35 PM, tomf...@thefsb.org wrote: i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large

Re: waling a directory with very many files

2009-06-16 Thread Nick Craig-Wood
Nick Craig-Wood n...@craig-wood.com wrote: Jean-Paul Calderone exar...@divmod.com wrote: On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood n...@craig-wood.com wrote: Hrvoje Niksic hnik...@xemacs.org wrote: Nick Craig-Wood n...@craig-wood.com writes: Here is a ctypes

Re: waling a directory with very many files

2009-06-15 Thread Nick Craig-Wood
tom f...@thefsb.org wrote: On Jun 14, 1:35 pm, Tim Golden m...@timgolden.me.uk wrote: If you're on Windows, you can use the win32file.FindFilesIterator function from the pywin32 package. (Which wraps the Win32 API FindFirstFile / FindNextFile pattern). thanks, tim. however, i'm

Re: waling a directory with very many files

2009-06-15 Thread Hrvoje Niksic
Terry Reedy tjre...@udel.edu writes: You did not specify version. In Python3, os.walk has become a generater function. So, to answer your question, use 3.1. os.walk has been a generator function all along, but that doesn't help OP because it still uses os.listdir internally. This means that

Re: waling a directory with very many files

2009-06-15 Thread Hrvoje Niksic
Nick Craig-Wood n...@craig-wood.com writes: Here is a ctypes generator listdir for unix-like OSes. ctypes code scares me with its duplication of the contents of system headers. I understand its use as a proof of concept, or for hacks one needs right now, but can anyone seriously propose using

Re: waling a directory with very many files

2009-06-15 Thread Nick Craig-Wood
Hrvoje Niksic hnik...@xemacs.org wrote: Nick Craig-Wood n...@craig-wood.com writes: Here is a ctypes generator listdir for unix-like OSes. ctypes code scares me with its duplication of the contents of system headers. I understand its use as a proof of concept, or for hacks one needs

Re: waling a directory with very many files

2009-06-15 Thread Jean-Paul Calderone
On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood n...@craig-wood.com wrote: Hrvoje Niksic hnik...@xemacs.org wrote: Nick Craig-Wood n...@craig-wood.com writes: Here is a ctypes generator listdir for unix-like OSes. ctypes code scares me with its duplication of the contents of system

Re: waling a directory with very many files

2009-06-15 Thread Terry Reedy
Christian Heimes wrote: Terry Reedy wrote: You did not specify version. In Python3, os.walk has become a generater function. So, to answer your question, use 3.1. I'm sorry to inform you that Python 3.x still returns a list, not a generator. type(os.walk('.')) class 'generator' However,

Re: waling a directory with very many files

2009-06-15 Thread Nick Craig-Wood
Jean-Paul Calderone exar...@divmod.com wrote: On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood n...@craig-wood.com wrote: Hrvoje Niksic hnik...@xemacs.org wrote: Nick Craig-Wood n...@craig-wood.com writes: Here is a ctypes generator listdir for unix-like OSes. ctypes code

Re: waling a directory with very many files

2009-06-15 Thread Mike Kazantsev
On Mon, 15 Jun 2009 15:35:04 -0400 Terry Reedy tjre...@udel.edu wrote: Christian Heimes wrote: Terry Reedy wrote: You did not specify version. In Python3, os.walk has become a generater function. So, to answer your question, use 3.1. I'm sorry to inform you that Python 3.x still

Re: waling a directory with very many files

2009-06-14 Thread Tim Golden
tom wrote: i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an object by walking a directory as a liked list. for

Re: waling a directory with very many files

2009-06-14 Thread tom
On Jun 14, 1:35 pm, Tim Golden m...@timgolden.me.uk wrote: If you're on Windows, you can use the win32file.FindFilesIterator function from the pywin32 package. (Which wraps the Win32 API FindFirstFile / FindNextFile pattern). thanks, tim. however, i'm not using windows. freebsd and os x. --

Re: waling a directory with very many files

2009-06-14 Thread Tim Golden
tom wrote: On Jun 14, 1:35 pm, Tim Golden m...@timgolden.me.uk wrote: If you're on Windows, you can use the win32file.FindFilesIterator function from the pywin32 package. (Which wraps the Win32 API FindFirstFile / FindNextFile pattern). thanks, tim. however, i'm not using windows. freebsd

Re: waling a directory with very many files

2009-06-14 Thread Andre Engels
On Sun, Jun 14, 2009 at 6:35 PM, tomf...@thefsb.org wrote: i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an

Re: waling a directory with very many files

2009-06-14 Thread Christian Heimes
tom schrieb: i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an object by walking a directory as a liked list.

Re: waling a directory with very many files

2009-06-14 Thread Terry Reedy
tom wrote: i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an object by walking a directory as a liked list. for

Re: waling a directory with very many files

2009-06-14 Thread Christian Heimes
Andre Engels wrote: What kind of directories are those that just a list of files would result in a very large object? I don't think I have ever seen directories with more than a few thousand files... I've seen directories with several hundreds of thousand files. Depending on the file system

Re: waling a directory with very many files

2009-06-14 Thread MRAB
Christian Heimes wrote: tom schrieb: i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an object by walking a

Re: waling a directory with very many files

2009-06-14 Thread Christian Heimes
Terry Reedy wrote: You did not specify version. In Python3, os.walk has become a generater function. So, to answer your question, use 3.1. I'm sorry to inform you that Python 3.x still returns a list, not a generator. ython 3.1rc1+ (py3k:73396, Jun 12 2009, 22:45:18) [GCC 4.3.3] on linux2

Re: waling a directory with very many files

2009-06-14 Thread Tim Chase
i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an object by walking a directory as a liked list. for example, in c,

Re: waling a directory with very many files

2009-06-14 Thread Steven D'Aprano
On Sun, 14 Jun 2009 22:35:50 +0200, Andre Engels wrote: On Sun, Jun 14, 2009 at 6:35 PM, tomf...@thefsb.org wrote: i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory.