Flatten complex directory structure in Python
问题 I want to move files from a complex directory structure to just one place. For example i have this deep hierarchy: foo/ foo2/ 1.jpg 2.jpg ... I want it to be: 1.jpg 2.jpg ... My current solution: def move(destination): for_removal = os.path.join(destination, '\\') is_in_parent = lambda x: x.find(for_removal) > -1 with directory(destination): files_to_move = filter(is_in_parent, glob_recursive(path='.')) for file in files_to_move: shutil.move(file, destination) Definitions: directory and glob