Web Analytics Made Easy -
StatCounter

Node Dangles

Quick & Dirty python recursive folder search

Someone asked how to have python recursively search a folder structure. There may be a better way but this is how I typically do it–it basically starts with one directory and loops through the contents compiling a list of sub-directories as it goes through the contents.

Options

import glob, os

theDir = 'c:/temp/'
theDirList = []
theDirList.append(theDir)

while len(theDirList)> 0:
   newDirList = []
   for iDir in theDirList:
      print iDir
      for iFile in glob.glob(iDir+"/*"):
         if (os.path.isdir(iFile)):
            newDirList.append(iFile)

   theDirList = newDirList
Menu