I have a large n-level directory structured as follows:
root | subdir1 | sub_subdir1 | ....(n-2 levels)..... | file1 | subdir2 | sub_subdir2 | ....(n-2 levels)..... | file2
I want to flatten the directory so that all level 1 subdirs contain files. I also want to remove the level 2 to (n-1) sub_subdirs as they contain no files. Please note that the subdirs all have different names.
root | subdir1 | file1 | subdir2 | file2
I have found a lot of posts explaining methods to flatten directories but none that explains how to do this in a controlled manner, i.e.,
- by specifying the levels to be flattened
- or doing it recursively for all sub_directories in a root directory