No such thing as a small change | |
PerlMonks |
Flattening a directory tree in a filesystemby steve (Deacon) |
on Jan 28, 2014 at 04:32 UTC ( [id://1072313]=perlquestion: print w/replies, xml ) | Need Help?? |
steve has asked for the wisdom of the Perl Monks concerning the following question: I have a directory in a filesystem (specifically linux/ext3 but the intent of the question is to be more generic) that potentially has a number of subdirectories and files at each level of the tree. I would like to essentially flatten this kind of structure and place all of the files in the topmost directory in the tree and remove all remaining (now empty) subdirectories. Aside: At some point I also want to add in the functionality to handle potential namespace collisions, but that seems much more simple.
As is almost always the case TIMTOWTDI, but I am seeking some wisdom in better practices from anyone who has done similar operations before. It seems that system, exec, etc. are wasteful as far as resources are concerned. Potentially I could write some recursive readdir-based function and use that to move any nodes of type file to the parent. Additionally there is a case to be made for using something like File::Find to make this happen as well. Please share what you know about a great way to address this problem.
Back to
Seekers of Perl Wisdom
|
|