logic - php - check for endless possibility and stop when reach the end -



logic - php - check for endless possibility and stop when reach the end -

i got folder construction so

css main.css home layout.css menu.css ... business relationship user.css menu.css user user.css level time.css ... ...

you can see lot of files , folders nested in each other. want loop through folder css, read every files , folders in it. if file, run function do(), if folder run function make() , go on loop through folder check files , folders inside. repeat process until there no more folder , file left loop through.

i can loop through files , folders if know how how many there are. problem don't know how many folders , files there are. there need special technique archive want ?

this perfect recursivedirectoriterator class comes php. it'll loop through each file , folder recursively. each item iterate through subclass of splfileinfo contains many function can utilize (e.g. getbasename(), getctime(), getextension(), , many more).

<?php $dir = '/path/to/folder'; $iterator = new recursiveiteratoriterator(new recursivedirectoryiterator($dir), recursiveiteratoriterator::child_first); foreach ( $iterator $path ) { // if it's directory. if ($path->isdir()) { // something. } else { // else. } }

php logic

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -