def file_opener(current_title, extension): for filename in os.listdir(dest): i = 0 if filename.endswith(file_type): pass if filename != current_title: pass if not filename.startswith(extension) and i == 0: O = Opener() path = os.path.join(dest, filename) O.open(path) i += 1 break