def find_files(path, search_files): result =[] for i in os.walk(path): if"debian"in i[0]: for item in i[2]: for file in search_files: if file in item and"swp"notin item: if os.path.join(i[0], item)notin result: result.append(os.path.join(i[0], item)) return result
files = find_files(search_path, search_file) for file in files: print file add_deb(file)