[Tutor] Question on Reading a Directory

Jeff Shannon jeff at ccvcorp.com
Mon Oct 27 21:52:20 EST 2003


P.T. Waugh MA wrote:

> Hi all,
> 
> I'm a very new Python programmer, and I want to get all the filenames 
> (Windows) into a list.  I have been unable to figure out how to do this 
> and don't see any functions in the library to do it.
> 
> Your help is appreciated.
> 
> Also, just out of curiousity.... this is how I copy a file:
> 
> splash = select_splash()
> win32file.CopyFile(splash, '..\\dlgsplash.bmp',0)
> 
> and I was just wondering, if I need to do it this way (as it seems 
> un-portable).

You want the os.listdir() function (to list the entire contents of a 
directory), or glob.glob() (to list filenames matching a filespec with 
wildcards).

For portable equivalents to most of the win32file functions, look in 
the os module and the shutil module.

Jeff Shannon
Technician/Programmer
Credit International





More information about the Tutor mailing list