I have a top folder named home
and nested folders and files inside
I need to insert some data from files and folders into a table
The following (simplified) code works fine if I manually declare parent folder for each level separatelly, i.e. – home/lorem/
, home/impsum/
, home/ipsum/dolor/
etc
Is there a way to do this automatically for all nested files and folders ?
Actually, I need the path for each of them on each level
$folders = glob("home/*", GLOB_ONLYDIR);
foreach($folders as $el){
//$path = ??;
//do_something_with folder;
}
$files = glob("home/*.txt");
foreach($files as $el){
//$path = ??;
//do_something_with file;
}
2
Answers
I would suggest you to use The Finder Component
PHP has the recursiveIterator suite of classes – of which the recursiveDirectoryIterator is the correct tool for the task at hand.