Long Chain of Nested Folders that are Empty except for One File at Bottom
by ericlindellnyc from LinuxQuestions.org on (#6PJ51)
dirA contains only dirB, which contains only dirC, which contains only dirD, which contains only filename.ext.
I have these long chains of otherwise empty folders -- sometimes 15 or 20 nesting levels. Scripts to remove empty folders don't work cuz of one file at bottom. I have scripts for just empty folders -- in python, bash -- & sometimes just macOS finder.
I haven't been able to find anything online, cuz any such attempt shows me how to remove empty folders, which I know how to do.
In python and bash, I find this varying of folder level in one script (or even just an iteration within a script) to be extremely challenging.
As always, assistance appreciated !! BTW, help on this forum is incredibly generous & valuable.
ADDITION.
I never clarified my goal. Above, we have
dirA contains only dirB, which contains only dirC, which contains only dirD, which contains only filename.ext.
I would like to move dirD into dirA.
Then I can delete empty folders, including dirB and dirC -- using my own script to move them to an external drive, so I can't accidentally delete the wrong folder.
There are tens of thousands of empty folders in these massive, ancient directory structures. I don't know how many of these peculiar chains exist -- but prbly a lot.
To be clear, I don't want to erase any files -- just re-arrange them.
Sorry for confusion.
I have these long chains of otherwise empty folders -- sometimes 15 or 20 nesting levels. Scripts to remove empty folders don't work cuz of one file at bottom. I have scripts for just empty folders -- in python, bash -- & sometimes just macOS finder.
I haven't been able to find anything online, cuz any such attempt shows me how to remove empty folders, which I know how to do.
In python and bash, I find this varying of folder level in one script (or even just an iteration within a script) to be extremely challenging.
As always, assistance appreciated !! BTW, help on this forum is incredibly generous & valuable.
ADDITION.
I never clarified my goal. Above, we have
dirA contains only dirB, which contains only dirC, which contains only dirD, which contains only filename.ext.
I would like to move dirD into dirA.
Then I can delete empty folders, including dirB and dirC -- using my own script to move them to an external drive, so I can't accidentally delete the wrong folder.
There are tens of thousands of empty folders in these massive, ancient directory structures. I don't know how many of these peculiar chains exist -- but prbly a lot.
To be clear, I don't want to erase any files -- just re-arrange them.
Sorry for confusion.