Hi, I'm pretty new to Python. Working in 2.4 due to company restraints. I'm trying to use os.path.walk to work through a tree directory, and perform different actions on the files based on the name of the file. I thought if I used "startwith" it would indicate that files only called "roads." would be processed. Unfortunatly it just goes ahead and processes all the files in the directories. I don't know a better way! Any help would be much appreciated.
The code has been simplified to just show this problem.
import sys, os def treeDir (arg, dirpath, basenames): workspace = dirpath for f in basenames: if f.startswith('roads.'): fullf = os.path.join(dirpath,f) try: # This space is for some some processing commands ## #Add A Completion Message print ("Well done. Now you can move on to the Next Big Thing") except: print ("Something's wrong") root = "C:\\scratch\\mine\\TEST" os.path.walk(root,treeDir,None)
Edited 4 Years Ago by kungfubambi: n/a