Sagewire Logo

SPL

5 Message(s) by 4 Author(s) originally posted in php general


From: borge Date:   Saturday, October 27, 2007
I'm current ly using RecursiveDirectoryIterator and RecursiveIteratorIterato=
r.
I'm using fwrite to write to a file while parsing throught the file structu=
re,=20
and was wondering if it is at all possible to sort alphabetical without goi=
ng=20
all array . That seems to me like doing the job twice over. Atleast part of=
=20
it...

=2D-=20
=2D--
B=F8rge Holen
http://www.arivene.net


From: quickshiftin Date:   Saturday, October 27, 2007
------=_Part_8844_31178005.1193527935776

Content-Disposition: inline

wrote in message:
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 o=
f
it...



how are you doing the sorting part?
can you show us some of your code ?

-nathan

------=_Part_8844_31178005.1193527935776--


From: jochem Date:   Saturday, October 27, 2007
wrote in message:
wrote in message:
wrote in message:
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 do not 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 not figure out how to make it read alphabeticly as mentioned
$it = new RecursiveDirectoryIterator($_GET['location']);



^-- you modified this part right?

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've a file stream open, I have no idea what a $path->__toString() results in
but I will assume it's the full path. whats to stop you seeking in the file and using
string comparison to find the correct position (ie. line) to inject a path.

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

-nathan





From: lists Date:   Sunday, October 28, 2007
wrote in message:
I found this code at php.net witch needs very little modifications and can do
so much, but I can not 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.
--
Jim Lucas "Perseverance isn't a long race;
it is many short races one after the other"

Walter Elliot
"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


From: quickshiftin Date:   Sunday, October 28, 2007
------=_Part_9950_6178259.1193582241316

Content-Disposition: inline
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

------=_Part_9950_6178259.1193582241316--



Next Message: libgmailer.php


Blogs related to SPL

Installing PHP 5.3 on Mac OSX
PHP 5.3 appeared on snaps.php.net today, and one of the features therein is namespacing. Now I've been curious about namespacing for some time - my code's currently full of class prefix_classname{} declarations - so I thought I'd like ...

Error using Hard SPL
Forum: Kaiser upgrading etc. Posted By: jrw2 Post Time: 24-10-2007 at 11:44 PM.

The Standard PHP Library
The goal of the Standard PHP Library-or SPL, for short-is to provide a standard library of interfaces that allows developers to take full advantage of object-oriented programming in PHP 5. This library of interfaces creates a standard ...

Crysis
Demo coming out in less than 10 hours. New desktop in place from Digital Asset pack. Cannot wait for this game, should be awesome and people with older systems should still have a great gaming experience unlike with the new Unreal ...

php shopping cart source code
... php spamassassin php spammer php special characters php special characters n php special chars php specified module could not be found php speedtest php spell check php spell check script php spell checker php spell checking php spl ...

http://www.php.net/%7Ehelly/php/ext/spl/
rocketmagnet : i'm more or less a php newbie (few month), i actualy write c for around 10 years now and started with scripting languages a few month ago rocketmagnet : stahlstift: i can't find the class rocketmagnet : only ArrayIterator ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional