def discover_files(base_path, sub_path='', ext='', trim_base_path=False):
 file_list = []
 for (root, dirs, files) in walk(path.join(base_path, sub_path)):
  if trim_base_path:
   root = path.relpath(root, base_path)
  file_list.extend([path.join(root, file_name) for file_name in files if file_name.endswith(ext)])
 return sorted(file_list)

def discover_files ( base_path , sub_path = '' , ext = '' , trim_base_path = False ) : file_list = [ ] for ( root , dirs , files ) in walk ( path . join ( base_path , sub_path ) ) : if trim_base_path : root = path . relpath ( root , base_path ) file_list . extend ( [ path . join ( root , file_name ) for file_name in files if file_name . endswith ( ext ) ] ) return sorted ( file_list )
discovers all files with certain extension in given paths .