FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » readdir lists randomly
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
readdir lists randomly [message #185199] Sat, 08 March 2014 15:01 Go to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
From the php manual


if ($handle = opendir('audio/1960')) {
echo "Directory handle: $handle\n";
echo "Entries:\n";

/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($handle))) {
echo "$entry\n";
echo "<br>";

}

closedir($handle);
}

Is there a way to list the entries according to the order they are listed
in the directory?
such as
60-001
60-002
60-003


http://mroldies.net/readdir.php
Re: readdir lists randomly [message #185200 is a reply to message #185199] Sat, 08 March 2014 15:15 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Saturday 08 March 2014 10:01, in comp.lang.php, "richard"
<noreply(at)example(dot)com> wrote:

> From the php manual
>
>
> if ($handle = opendir('audio/1960')) {
> echo "Directory handle: $handle\n";
> echo "Entries:\n";
>
> /* This is the correct way to loop over the directory. */
> while (false !== ($entry = readdir($handle))) {
> echo "$entry\n";
> echo "<br>";
>
> }
>
> closedir($handle);
> }
>
> Is there a way to list the entries according to the order they are listed
> in the directory?

Yes, use readdir(). readdir() reads directory entries in the same order as
they exist in the directory.

> such as
> 60-001
> 60-002
> 60-003

Oh, you mean in a specific *sorted* order, and not by the order that the
directory entries are recorded.

For that, you are going to have to read the directory and sort it.

Sorry
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: readdir lists randomly [message #185201 is a reply to message #185200] Sat, 08 March 2014 15:48 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Saturday 08 March 2014 10:15, in comp.lang.php, "Lew Pitcher"
<lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:

> On Saturday 08 March 2014 10:01, in comp.lang.php, "richard"
> <noreply(at)example(dot)com> wrote:
>
>> From the php manual
>>
>>
>> if ($handle = opendir('audio/1960')) {
>> echo "Directory handle: $handle\n";
>> echo "Entries:\n";
>>
>> /* This is the correct way to loop over the directory. */
>> while (false !== ($entry = readdir($handle))) {
>> echo "$entry\n";
>> echo "<br>";
>>
>> }
>>
>> closedir($handle);
>> }
>>
>> Is there a way to list the entries according to the order they are listed
>> in the directory?
>
> Yes, use readdir(). readdir() reads directory entries in the same order as
> they exist in the directory.
>
>> such as
>> 60-001
>> 60-002
>> 60-003
>
> Oh, you mean in a specific *sorted* order, and not by the order that the
> directory entries are recorded.
>
> For that, you are going to have to read the directory and sort it.

And, for that, you could use scandir()
See http://ca3.php.net/manual/en/function.scandir.php

--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: readdir lists randomly [message #185202 is a reply to message #185200] Sat, 08 March 2014 16:43 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
On Sat, 08 Mar 2014 10:15:39 -0500, Lew Pitcher wrote:

> On Saturday 08 March 2014 10:01, in comp.lang.php, "richard"
> <noreply(at)example(dot)com> wrote:
>
>> From the php manual
>>
>>
>> if ($handle = opendir('audio/1960')) {
>> echo "Directory handle: $handle\n";
>> echo "Entries:\n";
>>
>> /* This is the correct way to loop over the directory. */
>> while (false !== ($entry = readdir($handle))) {
>> echo "$entry\n";
>> echo "<br>";
>>
>> }
>>
>> closedir($handle);
>> }
>>
>> Is there a way to list the entries according to the order they are listed
>> in the directory?
>
> Yes, use readdir(). readdir() reads directory entries in the same order as
> they exist in the directory.
>
>> such as
>> 60-001
>> 60-002
>> 60-003
>
> Oh, you mean in a specific *sorted* order, and not by the order that the
> directory entries are recorded.
>
> For that, you are going to have to read the directory and sort it.
>
> Sorry

I can use it as is, just wasn't expecting the list to be shown that way.

Are you by any chance the same Lew Pitcher that is a radio dj in
Cincinnati?
Re: readdir lists randomly [message #185203 is a reply to message #185202] Sat, 08 March 2014 16:58 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Saturday 08 March 2014 11:43, in comp.lang.php, "richard"
<noreply(at)example(dot)com> wrote:
[snip]
> Are you by any chance the same Lew Pitcher that is a radio dj in
> Cincinnati?

Nope.

Although I do think it would have been fun to work at WKRP during the heydey
of Dr. Johnny Fever and Venus Flytrap. I always had a crush on Bailey.


--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: readdir lists randomly [message #185204 is a reply to message #185203] Sat, 08 March 2014 18:05 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
On Sat, 08 Mar 2014 11:58:42 -0500, Lew Pitcher wrote:

> On Saturday 08 March 2014 11:43, in comp.lang.php, "richard"
> <noreply(at)example(dot)com> wrote:
> [snip]
>> Are you by any chance the same Lew Pitcher that is a radio dj in
>> Cincinnati?
>
> Nope.
>
> Although I do think it would have been fun to work at WKRP during the heydey
> of Dr. Johnny Fever and Venus Flytrap. I always had a crush on Bailey.

Since you brought it up, I am in the first season!
I was driving taxis that year.
I was downtown apperaoching fountain square, stopped for the light and
noticed a guy standing beside a huge hollywood style camera on tripod.
The cab I was using that had a billboard on top of it for a local
restaurant chain. I was surprised to see my cab on the opening scenes!

Although the entire show was produced in Hollywood, the cast did make a
couple of short appearancces in Cinci.

When I mention the fact that WKRC-tv and WKRQ(fm) exist many people think
I'm joking. WEBN radio lays claim to the show being patterned after their
crazy antics they pull. But they weren't the only ones in town to do that
stuf.
The buikding they use in the show is just across the stree from WKRC-tv.
Re: readdir lists randomly [message #185303 is a reply to message #185199] Mon, 17 March 2014 11:05 Go to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
Am 08.03.2014 16:01, schrieb richard:

> From the php manual
>
>
> if ($handle = opendir('audio/1960')) {
> echo "Directory handle: $handle\n";
> echo "Entries:\n";
>
> /* This is the correct way to loop over the directory. */
> while (false !== ($entry = readdir($handle))) {
> echo "$entry\n";
> echo "<br>";
>
> }
>
> closedir($handle);
> }
>
> Is there a way to list the entries according to the order they are listed
> in the directory?
> such as
> 60-001
> 60-002
> 60-003

A directory does not have such "order". The sorting has to be done
afterwards.


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: [CM] Falkvinge: MtGox had custom SSHD written in PHP
Next Topic: Filling an array with random input doesn't quite work
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Apr 28 21:02:56 GMT 2024

Total time taken to generate the page: 0.02678 seconds