Newbie Question: Getting a list of files
Brian
desertlinux at netscape.net
Wed May 16 09:46:30 EDT 2007
Hi Steven,
Thanks for all of the good advice! Much appreciated.
Dusty
---
Steven D'Aprano wrote:
> On Tue, 15 May 2007 17:12:01 -0700, Brian wrote:
>
>> How do I, in Python, obtain a recursive list of files in a specified
>> directory, including the subdirectories, etc? For example, in the old
>> MS-DOS days, we could specify at the command prompt "DIR /S" and this
>> would provide a listing of all files, including those in subdirectories,
>> no matter how far down the branch they were. How can this be done with
>> Python?
>
> In MS DOS days, you were dealing with a small number of files. Python has
> to deal with file systems that could contain billions of files. If each
> file name has an average of eight characters, your recursive list of
> files could require a gigabyte of memory just to hold the file names. (It
> might not, of course -- it depends on the file system in use.)
>
> I suggest you have a look at the os module, in particular os.listdir and
> os.walk.
>
>
More information about the Python-list
mailing list