Re: SPL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Børge Holen wrote:
On Sunday 28 October 2007 07:27:53 you wrote:
Børge Holen wrote:
I found this code at php.net witch needs very little modifications and
can do so much, but I can't figure out how to make it read alphabeticly
as mentioned

		$it = new RecursiveDirectoryIterator($_GET['location']);
		foreach (new RecursiveIteratorIterator($it, 2) as $path){
			if($path->isDir()){
				// writing to some static file
			}elseif(some unfinished statement){
				fwrite($dynfile, "$path\n");
			}else{
				// writing to some static file
			}
		}

I just... nothings keeping me from sorting the the dynfile after writing,
but also that seems to do the job twice instead of doing it correct the
first time.

-nathan
I am trying to figure out what you are trying to do here.

The code is for recursiving directory structure.
Starting at a given location




Ok, so, let me get this straight.

You want the ability to display alphabetically, the files/directories of a given directory and all sub-directories?

Now, do you want this echo'ed to the screen, or saved in a file like you did in your earlier example?

either way, the following code will help you I think.

<?php

function displayDirectory($path) {
	$data = glob($path.'/*');
	foreach ( $data AS $entry ) {
		if ( in_array($entry, array('./', '../')) ) {
			continue;
		}
		if ( is_dir($entry) ) {
			displayDirectory($entry);
		} else {
			echo "{$entry}\n";
		}
	}
}

displayDirectory($_GET['location']);


--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux