fileorder?

This is a discussion on fileorder? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, I'm reading out some files from a directory with: $handle=OpenDir (PicDir); /* Verzeichnis �fnen und ein handle erstellen ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-26-2005
roN
 
Posts: n/a
Default fileorder?

Hi,
I'm reading out some files from a directory with:
$handle=OpenDir (PicDir); /* Verzeichnis �fnen und ein handle
erstellen welches daraufzeigt */
$PicArray=array(); /* Array erstellen, in welchem sp�er die Bilddaten
gespeichert werden */
while($tmpPic=readdir ($handle)) /* schleife durchlaufen, bis alle Dateien
durch sind */
{
if (FileExt_Check("jpg",$tmpPic)) /* berprfen ob die File-Extension *.jpg
ist...*/
{
array_push($PicArray,$tmpPic); /* Dateinamen des Bildes in Array
kopieren */
}
}
In what order are they read out? I'm not able to figure it out. Am I able to
modify it anyway?
Thank you!
--
chEErs roN

I'm root, I'm allowed to do this! ;)
keep on rockin'
Reply With Quote
  #2 (permalink)  
Old 09-26-2005
Stefan Rybacki
 
Posts: n/a
Default Re: fileorder?

roN wrote:
> Hi,
> I'm reading out some files from a directory with:
> $handle=OpenDir (PicDir); /* Verzeichnis �fnen und ein handle
> erstellen welches daraufzeigt */
> $PicArray=array(); /* Array erstellen, in welchem sp�er die Bilddaten
> gespeichert werden */
> while($tmpPic=readdir ($handle)) /* schleife durchlaufen, bis alle Dateien
> durch sind */
> {
> if (FileExt_Check("jpg",$tmpPic)) /* berprfen ob die File-Extension *.jpg
> ist...*/
> {
> array_push($PicArray,$tmpPic); /* Dateinamen des Bildes in Array
> kopieren */
> }
> }
> In what order are they read out? I'm not able to figure it out. Am I able to
> modify it anyway?


Nope. I guess its sorted by creation time or maybe by position in a FAT. To sort it read
all files and sort it yourself.

Regards
Stefan


> Thank you!

Reply With Quote
  #3 (permalink)  
Old 09-27-2005
roN
 
Posts: n/a
Default Re: fileorder?

[snip]
>
> Nope. I guess its sorted by creation time or maybe by position in a FAT.
> To sort it read all files and sort it yourself.


oh :( that sucks... :(

--
chEErs roN

I'm root, I'm allowed to do this! ;)
keep on rockin'
Reply With Quote
  #4 (permalink)  
Old 09-27-2005
roN
 
Posts: n/a
Default Re: fileorder?

roN wrote:

> [snip]
>>
>> Nope. I guess its sorted by creation time or maybe by position in a FAT.
>> To sort it read all files and sort it yourself.

>
> oh :( that sucks... :(

Hm, anyway, I did it like this.
Is it possible to sort it for more conditions like just the alphabetical one
with sort()? I'd like to sort the items in the Array
1st: by a containing String (like if tex contain the word "test" they should
come first)
2nd: Alphabetical listening
Thank you again!
--
chEErs roN

I'm root, I'm allowed to do this! ;)
keep on rockin'
Reply With Quote
  #5 (permalink)  
Old 09-27-2005
Stefan Rybacki
 
Posts: n/a
Default Re: fileorder?

roN wrote:
> roN wrote:
>
>
>>[snip]
>>
>>>Nope. I guess its sorted by creation time or maybe by position in a FAT.
>>>To sort it read all files and sort it yourself.

>>
>>oh :( that sucks... :(

>
> Hm, anyway, I did it like this.
> Is it possible to sort it for more conditions like just the alphabetical one
> with sort()? I'd like to sort the items in the Array
> 1st: by a containing String (like if tex contain the word "test" they should
> come first)
> 2nd: Alphabetical listening


Sure that is possible
- find a sort function of php that supports a callback function where you can say which of
two items is greater
- or if there is not such a function write a quicksort by yourself (isn't hard) and use a
callback function for the comparison of two items

in the callback function you first check for your search text "test" the element that has
this text is smaller than the one without, if both items have this text or both haven't
you sort by alphabet.


Regards
Stefan


> Thank you again!

Reply With Quote
  #6 (permalink)  
Old 09-29-2005
roN
 
Posts: n/a
Default Re: fileorder?

Stefan Rybacki wrote:

> roN wrote:
>> roN wrote:
>>
>>
>>>[snip]
>>>
>>>>Nope. I guess its sorted by creation time or maybe by position in a FAT.
>>>>To sort it read all files and sort it yourself.
>>>
>>>oh :( that sucks... :(

>>
>> Hm, anyway, I did it like this.
>> Is it possible to sort it for more conditions like just the alphabetical
>> one with sort()? I'd like to sort the items in the Array
>> 1st: by a containing String (like if tex contain the word "test" they
>> should come first)
>> 2nd: Alphabetical listening

>
> Sure that is possible
> - find a sort function of php that supports a callback function where you
> can say which of two items is greater


is uksort() such a function?

> - or if there is not such a function write a quicksort by yourself (isn't
> hard) and use a callback function for the comparison of two items
>
> in the callback function you first check for your search text "test" the
> element that has this text is smaller than the one without, if both items
> have this text or both haven't you sort by alphabet.


may you help me a bit further please?
Thank you!

--
chEErs roN

I'm root, I'm allowed to do this! ;)
keep on rockin'
Reply With Quote
  #7 (permalink)  
Old 09-29-2005
roN
 
Posts: n/a
Default Re: fileorder?

wouldn't a sort-algorithm like this work:
function MySort($Array, $StringA)
{
$i=Array;
for ($i=0; $i>=Array.size(); $i++)
{
while (strpos($Array[$i],$StringA))//if Array $i contains StringA,
{
move Element $i to $i+1; and
move $i+1 to $i;
}
}
}
but how to move the elements?
--
chEErs roN

I'm root, I'm allowed to do this! ;)
keep on rockin'
Reply With Quote
  #8 (permalink)  
Old 10-01-2005
roN
 
Posts: n/a
Default Re: fileorder?

roN wrote:

> wouldn't a sort-algorithm like this work:
> function MySort($Array, $StringA)
> {
> $i=Array;
> for ($i=0; $i>=Array.size(); $i++)
> {
> while (strpos($Array[$i],$StringA))//if Array $i contains StringA,
> {
> move Element $i to $i+1; and
> move $i+1 to $i;
> }
> }
> }
> but how to move the elements?


Well, can't you help me anymore?
--
chEErs roN

I'm root, I'm allowed to do this! ;)
keep on rockin'
Reply With Quote
  #9 (permalink)  
Old 10-01-2005
Stefan Rybacki
 
Posts: n/a
Default Re: fileorder?

roN wrote:
> roN wrote:
>
>
>>wouldn't a sort-algorithm like this work:
>>function MySort($Array, $StringA)
>>{
>> $i=Array;
>> for ($i=0; $i>=Array.size(); $i++)
>> {
>> while (strpos($Array[$i],$StringA))//if Array $i contains StringA,
>> {
>> move Element $i to $i+1; and
>> move $i+1 to $i;
>> }
>> }
>>}
>>but how to move the elements?

>
>
> Well, can't you help me anymore?



I can.

uksort is such a function, but you need usort.

Use a compare function like this:

function mycompare ($a, $b) {
//first check for search text in $a and $b
$isInA=(strpos($a,'test')!==false);
$isInB=(strpos($b,'test')!==false);

//so if $isInA==$isInB then compare alphabetical
if ($isInA == $isInB) {
if ($a == $b) return 0;
return ($a > $b) ? 1 : -1;
} else {
//the one that is true comes first
return ($isInA) ? -1:1;
}

return 0;
}

this function sorts entries with 'test' in it to the front and alphabetical in case of
more than one entries containing this text or in case that there is no 'test' in that entry.

use it like this:

usort($PicArray,"mycompare");

BTW: your commentaries are in german, may you better switch to english very soon


Regards
Stefan
Reply With Quote
  #10 (permalink)  
Old 10-02-2005
roN
 
Posts: n/a
Default Re: fileorder?

Stefan Rybacki wrote:

> roN wrote:
>> roN wrote:
>>
>>
>>>wouldn't a sort-algorithm like this work:
>>>function MySort($Array, $StringA)
>>>{
>>> $i=Array;
>>> for ($i=0; $i>=Array.size(); $i++)
>>> {
>>> while (strpos($Array[$i],$StringA))//if Array $i contains
>>> StringA,
>>> {
>>> move Element $i to $i+1; and
>>> move $i+1 to $i;
>>> }
>>> }
>>>}
>>>but how to move the elements?

>>
>>
>> Well, can't you help me anymore?

>
>
> I can.
>
> uksort is such a function, but you need usort.
>
> Use a compare function like this:
>
> function mycompare ($a, $b) {
> //first check for search text in $a and $b
> $isInA=(strpos($a,'test')!==false);
> $isInB=(strpos($b,'test')!==false);
>
> //so if $isInA==$isInB then compare alphabetical
> if ($isInA == $isInB) {
> if ($a == $b) return 0;
> return ($a > $b) ? 1 : -1;
> } else {
> //the one that is true comes first
> return ($isInA) ? -1:1;
> }
>
> return 0;
> }
>
> this function sorts entries with 'test' in it to the front and
> alphabetical in case of more than one entries containing this text or in
> case that there is no 'test' in that entry.
>
> use it like this:
>
> usort($PicArray,"mycompare");
>
> BTW: your commentaries are in german, may you better switch to english
> very soon


erm what commentaries?
and thank you very much for your help!
I think I'll get it done now :)
my array looks like this:
p1010001-05-09-03.jpg
p1010001-05-09-04.jpg
p1010001-05-09-05,06.jpg
p1010001-05-09-07,08,09.jpg
p1010001-05-09-12.jpg
p1010001-05-09-13,14.jpg
p1010001-rest.jpg
p1010002-05-09-03.jpg
p1010002-05-09-04.jpg
p1010002-05-09-05,06.jpg
p1010002-05-09-07,08,09.jpg
p1010002-05-09-12.jpg
p1010002-05-09-13,14.jpg
....
....
....
and i would like to sort it like this:
p1010001-05-09-03.jpg
p1010002-05-09-03.jpg
p1010001-05-09-04.jpg
p1010002-05-09-04.jpg
p1010001-05-09-05,06.jpg
p1010002-05-09-05,06.jpg
p1010001-05-09-07,08,09.jpg
p1010002-05-09-07,08,09.jpg
p1010001-05-09-12.jpg
p1010002-05-09-12.jpg
p1010001-05-09-13,14.jpg
p1010002-05-09-13,14.jpg
p1010001-rest.jpg
....
....
....

how do I have to manipulate the function you provided to do that?
Did you get the order by the way? first ordered by umber then by date...
Thank you again! :)
--
chEErs roN

I'm root, I'm allowed to do this! ;)
keep on rockin'
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:03 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0