Newbie Question: Getting a list of files

John Machin sjmachin at lexicon.net
Tue May 15 20:45:36 EDT 2007


On May 16, 10:12 am, Brian <desertli... at netscape.net> wrote:
> Hello,
>
> I am currently working on putting together a free, open source,
> anti-spyware program for the Mac (and eventually for other OS's too.)
> However, there's one thing that I am currently trying to figure out:
>
> 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?
>
> P.S. I have been searching Google, but haven't found the answer yet.
>

Try reading the Python docs instead :-)
In general, anyone doing anything much with files and directories
should know what's in the os and os.path modules.
In particular, os.walk is probably what you are looking for.

HTH,
John




More information about the Python-list mailing list