[Tutor] List files in directory

Bernard Lebel python at bernardlebel.com
Sun Aug 15 23:50:43 CEST 2004


Thank you very much, glad my question was simple enough to get help ;-)


Bernard


----- Original Message ----- 
From: "EJP" <ejp at zomething.com>
To: "Bernard Lebel" <python at bernardlebel.com>; <tutor at python.org>
Sent: Sunday, August 15, 2004 9:22 PM
Subject: Re: [Tutor] List files in directory


"Bernard Lebel" wrote:

>
> Hello,
>
> Anyone has advice on how to collect filenames from a directory?

<snip>

> I want to print only the files contains in the currently visited
directory.


This is simple enough that I can help:

import os
path="C:\\somedirectory"  # insert the path to the directory of interest
here
dirList=os.listdir(path)
for fname in dirList:
    print fname




More information about the Tutor mailing list