faqts : Computers : Programming : Languages : Python : Common Problems : Files

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

22 of 27 people (81%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How do I get a list of files in a parent directory and its subdirectories

Feb 15th, 2004 10:58
Washington Corrêa, Sam G,


Here it goes:
import os
def getFiles(parent):
  arqs = os.listdir(parent)
  for a in arqs:
  if os.path.isdir(parent + "/" + a):
    getFiles(parent + "/" + a)
  else:
    print parent + "/" + a
Of course, this will only print to the output device, but you can modify
it to build a list or anything you want.
ok?
Junior