Perl-Sensitive Sunglasses | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
OK I like to know how things work so although you can and probably should do this with a module here is how you do it.
How we do it is simple. First we define our root dir and our delimiter and push this into the @dirs array. We then iterate over the @dirs array. Although @dirs initially only contains the root dir we find all its subdirs and push them onto the end of this. Thus after the first iteration @dirs contains all the subdirs of our root dir which we then search for subdirs and so on ad infinitum until we have no more subdirs. Testing for the . and .. dirs is important as these are the current and one level up dirs. Using eq is better than a regex as you can fool a regex using a newline in a dirname (which is valid). We do not want to follow symbolic links otherwise we may end up in an infinite loop. This is what the guys allude to above. We then test each file to see if it is a direcory or a file and push it into the appropriate array. By the fime we have iterated over @dirs we have all the directories in @dirs and all the files in @files. These are the fullly specified paths. You can then do whatever you like with them. Hope this helps. cheers tachyon s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print In reply to Re: Recursion
by tachyon
|
|