This works without any extra package. It is rather straight-forward, anyway.
Main Topics
Browse All TopicsI am looking (without installing extra packages) to get an array to have a directory structure of a bunch of folders then go through each folder and list the files, (and also know the directory its in)
Take the following file paths (starting from 'My Photos' for instance):
/home/tim/my photos/
/home/tim/my photos/journey/1.jpg
/home/tim/my photos/journey/2.jpg
/home/tim/my photos/journey/3.jpg
/home/tim/my photos/birthday/1.jpg
/home/tim/my photos/birthday/2.jpg
/home/tim/my photos/birthday/3.jpg
I would like to find the code that makes me an array of the directorys (recursively) in a given path - in the above example I would like @dirs = ("/home/tim/my photos/journey/" , "/home/tim/my photos/birthday/")
Then I want to get the full file paths into another array... so @files = ("/home/tim/my photos/journey/1.jpg","/ho
I know this should be easy but I can't find a straightforward approach, I don't wish to have it rely on other packages as it has to run from different web servers which won't let me install extra packages from CPAN etc.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Both answers worked for me, but the first answer by mrjoltcola was easier to implement into my own program. However the second one doesn't use any other packages at all! luckily File::find seems to be installed by default :)
I don't quite understand whats going on the last part of the recurse sub (at row 12) on the second example as that seems outside what I know, do you have the time to elaborate on what it means for me ?
cheers!!
/[^.]/
Match only strings with at least one character that's not a dot. This is to prevent an infinite loop into directory '.'
-d "$base/$_"
Returns true if "$base/$_" is a directory, other wise false.
grep { /[^.]/ && -d "$base/$_" } @dircontents
Filter all entries in the current directory that are directores themselves, but not '.' and '..'
foreach grep { /[^.]/ && -d "$base/$_" } @dircontents
Iterate over all those filtered directories...
recurse("$base/$_") foreach grep { /[^.]/ && -d "$base/$_" } @dircontents;
...and iteratively call the recurse function with the filtered directories as arguments.
Business Accounts
Answer for Membership
by: mrjoltcolaPosted on 2009-04-05 at 06:56:51ID: 24071521
Hope this gets you startred.
Select allOpen in new window