This is similar to What's the Ruby equivalent of Python's os.walk?, but I'm interested in walking the directory tree from the leaves back, rather than the root out.
I.e., for a directory structure like
/root/
|- A/
|- a.txt
|- B/
|- b.txt
|- C/
|- c.txt
Given root
, I'd like to traverse it in the following order.
- /root/A/a.txt
- /root/A
- /root/B/C/c.txt
- /root/B/C
- /root/B/b.txt
- /root/B
I need to replace file content and rename both files and directories during the traversal, so variations on that order would be OK. Because of the directory renaming, starting at the root directory isn't an attractive option.