How to list files, folders and all their files under the folders
Ben
b.e.n. at .r.e.h.a.m.e...c.o.m
Mon May 21 19:53:43 EDT 2001
Using os.path.walk you can traverse a directory tree and return all
directories and files to a list ... the below example takes it a step
further and generates fullpath names in the list DirectoryList
import os
DirectoryToWalk='c:\\Test\\' #Specify Directory To Traverse
def walker(arg, dirname, filenames):
# Create A List Of Files with full pathname
for files in filenames:
arg.append(os.path.join(dirname, files))
DirectoryList = [] #Write Full Pathnames Here
os.path.walk(DirectoryToWalk, walker, DirectoryList)
Hope this helps
Ben
On Mon, 21 May 2001 21:55:10 GMT, "Jennifer Jeng"
<jeng at cliffie.nosc.mil> wrote:
>Hi,
>Is there a way to list all files, folders and all the files under those
>folders using python.
>
>Thanks.
>
More information about the Python-list
mailing list