Re: SPL

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

 



On Sunday 28 October 2007 02:57:13 Jochem Maas wrote:
> Børge Holen wrote:
> > On Sunday 28 October 2007 01:32:15 you wrote:
> >> On 10/27/07, Børge Holen <borge@xxxxxxxxxxx> wrote:
> >>> I'm currently using RecursiveDirectoryIterator and
> >>> RecursiveIteratorIterator.
> >>> I'm using fwrite to write to a file while parsing throught the file
> >>> structure,
> >>> and was wondering if it is at all possible to sort alphabetical without
> >>> going
> >>> all array. That seems to me like doing the job twice over. Atleast part
> >>> of it...
> >>
> >> how are you doing the sorting part?
> >> can you show us some of your code ?
> >
> > thats the problem, i don't know how to sort before read starts, that came
> > out a bit wrong. I need to read the filesystem alphabeticly.
> >
> > I could use the system command 'find somepath' and then use '| sort'
> > witch was part of my old stuff with a ton of waste code.
> > or I could 'sort array' witch of course forces me to create an array to
> > loop around and push at each folder and leaf.
> >
> > 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']);
>
> 							^-- you modified this part right?

yes I did, it is wrong all together and is supposed to be like this
$it = new RecursiveDirectoryIterator('/store'.$_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.
>
> you have a file stream open, I have no idea what a $path->__toString()
> results in but I'll assume it's the full path. 

Yes it will only show me the folder structure, ie. no files. Here I have some 
unfinished string work to do, but in each of those if elseif and else I want 
to sort.

> whats to stop you seeking in 
> the file and using string comparison to find the correct position (ie.
> line) to inject a path.

Here I wrote a lot of execuse why I didn't do that, I changed my mind after 10 
lines, I love that Idea, I just thought like make an appendix for each 
append. This is not probably what you was thinking of, but I'm going to use 
that one. Thats for appending though, what about each time I write a new 
file, and the file is empty.
Searching for position here probably isn't the best solution since the fastest 
method is just to start read it right.


> so basically sort as you write into the file, how to do this efficiently
> is another question. :-)

fwrite($dynfile, "$path\n");
this works satisfyingly, short pretty 1line. BUT I'm always in for suggestions

>
> >> -nathan



-- 
---
Børge Holen
http://www.arivene.net

-- 
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