![]() |
Glob recursion not working right
I need to be able to read through all directories in a given path and list all of the files. I'm using the following code and it works for the top level but not sub-directories. For example, if there is this structure
Code:
dirAPHP Code:
|
It seems a bit of a convoluted method of traversing the directories, especially with changing the current working directory so often. You could change the call to the second
glob (in the foreach) to use full (or relative) paths rather than just *. Or you could use the handy RecursiveDirectoryIterator which makes life easier. |
I'm not sure I understand how to make that change but I tried the following. The result is the same though. The sub-directories are listed but not their contents. This is actually the code I started with but when it didn't work, I added the recursive call to try to get in to the sub-directory.
As for RecursiveDirectoryIterator, I used that first and it did work in some cases. But besides it requiring php 5, the main problem is that it was causing an out of memory condition. That may have been due to the part of the code not shown where the contents of the files are read, but I decided to make it php 4 compatible and switched to the glob function. PHP Code:
|
| All times are GMT. The time now is 02:53 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0