Just to simplify little and use better names.
import os
for root, dirs, files in os.walk(r'C:\test'):
for f in files:
if f.startswith('roads.'):
print f
#print os.path.join(root, f)
So this will print only files that starswith "roads" in directory c:\test.
we iterate over files and last line we can join root(path) with filename.
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294
Everything should go under the if statement (indents count in Python), or copy the file you want to process to a list and process the list.
def treeDir (arg, dirpath, basenames):
workspace = dirpath
roads_list = []
for f in basenames:
if f.startswith('roads.'):
fullf = os.path.join(dirpath,f)
function_to_process_this_file(fullf)
##
## or
roads_list.append(fullf)
## all files are processed
for fname in roads_list:
function_to_process_this_file(fname)
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714