flyhoney Posted February 12, 2008 Share Posted February 12, 2008 This is really more of an algorithm question, but I'm doing it in PHP and maybe some of you out there just love problem solving. I want to read a list of filenames into an array that reflects the directory structure. The list looks something like this: C:\this\file1.ext C:\this\file2.ext C:\this\that\file3.ext C:\foo\file6.ext . . etc And I want to read it into an array so that it looks like this: Array ( [C:] => Array ( [this] => Array ( [0] => file1.ext [1] => file2.ext [that] => Array ( [0] => file3.ext ) ) [foo] => Array ( [0] => file6.ext ) ) ) I know there is probably a nice recursive solution to this, but I keep screwing it up. If anyone knows how to do this off the top of their head, it would be a great help. If you can think of a better data structure to store the directory information in just let me know. Quote Link to comment https://forums.phpfreaks.com/topic/90726-read-directory-structure-into-array/ Share on other sites More sharing options...
trq Posted February 12, 2008 Share Posted February 12, 2008 I know there is probably a nice recursive solution to this, but I keep screwing it up. Show us what youv'e got. Quote Link to comment https://forums.phpfreaks.com/topic/90726-read-directory-structure-into-array/#findComment-465065 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.