[Tutor] os.path.walk vs unix find command
angelayian at yahoo.com
Sat Aug 16 00:17:10 CEST 2008
Hi Python gurus:
Is os.popen("find") faster or slower than os.path.walk to find file pattern in the
directory tree? I thought os.path.walk would be faster than unix find, but that doesn't
seem to be the case?
What is the fastest way in python to search for a file with a given pattern in a directory
Here's the code using os.path.walk:
def find_src_mk_file(walk_lst_result, dirname, fnames):
x = len(dirname)
if (dirname[x-4:x] == "/src"):
result = glob.glob(os.path.join(dirname, "src.mk"))
walk_lst_result = 
os.path.walk( component_dir, find_src_mk_file, walk_lst_result )
# check each src.mk and remove from lst
for sub_file_src_mk in walk_lst_result:
Anything wrong with this code? Please advise.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor