I wrote a script that recursively reads the contents of a folder and outputs the names and permissions of the files contained in that folder.
If the folder contains a subfolder, what I'd like it do to is open the subfolder and do the same check for the files inside that subfolder.
Unfortunately right now when I loop through the contents of the folder a subfolder is recognized as a file, rather than a folder and so my script doesn't know to open the subfolder. I am not sure what I am doing wrong. I am using the function is_dir() to check whether the contents of the folder are files or subfolders but apparently in that loop all folders and files don't satisfy that condition and is_dir() returns false for all of them.
How can I circumvent this?
[RESOLVED] is_dir() returns false for subfolder, how to check for folders in a recursive loop?
You might use is_dir(filename)
This will work as long as your script is targetting current working directory.
For subdirectory you need to add path to the filename
ah ha!
thanks for the quick reply...
I did not have the path specified, I thought I didn't need to!
Thanks a lot halojoy!
marcnyc;10942679 wrote:ah ha!
thanks for the quick reply...
I did not have the path specified, I thought I didn't need to!
Thanks a lot halojoy!
Was not long ago I did the same mistake :rolleyes:
This is why I know.
It is by our mistakes we learn the best.
we all learn from those