We have a whole bunch of files and we want to crawl through them and list them.
Crawling through folders
This can be done using the
walk() function in the
os python module.
You can read all about it here, but you basically end up with a tuple, containing the directory path, the directory names, and the file names.
We are interested in the directory paths and the file names.
So to crawl through them you can run this script.
import os for dirPath,dirNames,filName in os.walk('.'): for theFile in filName: if theFile.endswith('.py'): print os.path.join(dirPath,theFile)
./testa.py ./testb.py ./fold1/test1.py ./fold2/test2.py ./fold3/test3.py