Re: SPL

From: Date: Sun, 28 Oct 2007 19:29:28 +0000
Subject: Re: SPL
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-263765@lists.php.net to get a copy of this message
On Sunday 28 October 2007 15:37:21 Nathan Nobbe wrote: > i suppose this is what youre looking for ? > you can tailor it to your needs of course :) > > <?php > $it = new RecursiveDirectoryIterator('.'); > $isFirstDir = true; > $fileList = array(); > $dynfile = fopen('sortedFiles', 'w+'); > $theRecursiveIteratorIterator = > new RecursiveIteratorIterator($it, > RecursiveIteratorIterator::CHILD_FIRST); > > foreach ($theRecursiveIteratorIterator as $path){ > if($path->isDir()){ > /// drop the name of the directory into the results > fwrite($dynfile, 'Directory: ' . (string) $path . PHP_EOL); > if($isFirstDir) { // just update the flag on the > first dir > $isFirstDir = false; > } else { > sort($fileList); // sort the list however > you like > /// iterate over the sorted list, placing them in > the output file > foreach($fileList as $sortedDirFile) { > fwrite($dynfile, $sortedDirFile . PHP_EOL); > } > $fileList = array(); // clear the list for the > next directory > } > }else{ /// place the current path to a file in the list > $fileList[] = (string) $path; > } > } > fclose($dynfile); > ?> > > > -nathan both yes and no. Yes I can modify this 'n put it to good use, and no I'm stille buggered with creating array just to print it again, when I could've writting it instead of filling the array. -- --- Børge Holen http://www.arivene.net

« previous php.general (#263765) next »