473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

"asort" is not doing what it is supposed to do

Hello everybody,

I have this problem reading the contents of a directory. here is my code:

$my_dir = dir('data/templates');

asort($my_dir);

while (false !== ($entry = $my_dir->read()))
{
echo $entry."<br>\n";
}
$my_dir->close();
But I need it to read the directory in alphabetical order and I cannot
succeed in this. "asort" is not doing what it is supposed to do. Can
somebody tell me how to achieve this?

Thank you

Françoise
Feb 13 '07 #1
8 1818
Françoise Debat wrote:
I have this problem reading the contents of a directory. here is my code:

$my_dir = dir('data/templates');

asort($my_dir);
Eeeerrr.... $my_dir is not an array, you cannot run asort() through it!!

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_*************************@hotmail.com
Jabber:iv*********@jabber.org ; iv*********@kdetalk.net
Feb 13 '07 #2
Iván Sánchez Ortega wrote:
Françoise Debat wrote:
>I have this problem reading the contents of a directory. here is my code:

$my_dir = dir('data/templates');

asort($my_dir);

Eeeerrr.... $my_dir is not an array, you cannot run asort() through it!!
Yes, I understand. How then can I sort the list alphabetically?

Thanks for your help

Françoise
Feb 13 '07 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Françoise Debat wrote:
>Eeeerrr.... $my_dir is not an array, you cannot run asort() through it!!

Yes, I understand. How then can I sort the list alphabetically?
First dump all the directory entries in an array, *then* sort that array.

- --
- ----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

http://acm.asoc.fi.upm.es/~mr/
Proudly running Debian Linux with 2.6.17-1-686 kernel, KDE3.5.3, and PHP
5.2.0-8 generating this signature.
Uptime: 20:18:05 up 4:55, 1 user, load average: 0.56, 0.48, 1.01

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFF0g81R56dWuhgxGgRAngmAKDBYZXvHH2dQNjTRo2D0S 4qDCrJwACdFAYs
Tif9X54tZaT43WaH6JjJA/s=
=ikhC
-----END PGP SIGNATURE-----
Feb 13 '07 #4
Message-ID: <eq**********@hercules.cohp1from Iván Sánchez Ortega
contained the following:
>Yes, I understand. How then can I sort the list alphabetically?

First dump all the directory entries in an array, *then* sort that array.
That's probably easiest. Might be more fun to do a bubble sort though
:-)

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Feb 13 '07 #5
Geoff Berrow wrote:
Message-ID: <eq**********@hercules.cohp1from Iván Sánchez Ortega
contained the following:
>>Yes, I understand. How then can I sort the list alphabetically?
First dump all the directory entries in an array, *then* sort that array.

That's probably easiest. Might be more fun to do a bubble sort though
:-)
I'm sorry, I don't understand how to do either. Please can you point me
to an example I can learn from?

Thank you very much

Françoise
Feb 13 '07 #6
Message-ID: <45**********************@news.orange.frfrom Françoise
Debat contained the following:
>>
That's probably easiest. Might be more fun to do a bubble sort though
:-)

I'm sorry, I don't understand how to do either. Please can you point me
to an example I can learn from?
<?php

$path=$_SERVER['PATH_TRANSLATED'];
$dir=dirname($path);
$directory=str_replace("/","",strrchr($dir, "/"));
echo"<h2>Files in $directory</h2>\n\n";
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
//print $dir . $file;
if($file!="." && $file!=".." ){
$files[]=$file;
}
}
asort($files);
closedir($dh);
}
foreach($files as $value){
echo $value."<br>";
}

?>
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Feb 14 '07 #7
Geoff Berrow wrote:
Message-ID: <45**********************@news.orange.frfrom Françoise
Debat contained the following:
>>That's probably easiest. Might be more fun to do a bubble sort though
:-)
I'm sorry, I don't understand how to do either. Please can you point me
to an example I can learn from?

<?php

$path=$_SERVER['PATH_TRANSLATED'];
$dir=dirname($path);
$directory=str_replace("/","",strrchr($dir, "/"));
echo"<h2>Files in $directory</h2>\n\n";
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
//print $dir . $file;
if($file!="." && $file!=".." ){
$files[]=$file;
}
}
asort($files);
closedir($dh);
}
foreach($files as $value){
echo $value."<br>";
}

?>
I cannot thank you enough - thank you so much.

Regards

Françoise
Feb 14 '07 #8
Message-ID: <45**********************@news.orange.frfrom Françoise
Debat contained the following:
>I cannot thank you enough - thank you so much.
You are welcome. :-)

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Feb 14 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: aa | last post by:
Is a PHP variable supposed to be seen in a .js file included into a .php file? I have a client side javascript code stored in a .js file which is included into a PHP file using <script...
3
by: Gianni Mariani | last post by:
This is one of those, hugh ? moments. So, GCC behaves just like I would kinda expect it to but it looks VERY strange. It's one of those things that could cause silent strife if you included...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
3
by: needin4mation | last post by:
Hi, I have an asp:button that has a ShowModalDialog script attribute added to it. When the ShowModalDialog opens the user is supposed to select some data which is then sent back to the calling...
17
by: Benny Raymond | last post by:
I have a thread that sleeps for 5 minutes once it's finished running a method and then it repeats itself if it's supposed to (bool = true). Prior to 2.0 I was able to resume the thread after...
14
by: spibou | last post by:
What is strcmp supposed to return if one or both arguments passed to it are NULL ?
11
by: justsome_newbie | last post by:
Hello experts! I'm trying to send mail from my C# Asp.Net webpage. I used the code samples at www.systemnetmail.com but it still won't send. I think the problem is on the iis or exchange server...
15
by: robert maas, see http://tinyurl.com/uh3t | last post by:
Here's the source: #include <stdio.h> #include <errno.h> main () { char* str = "9999999999"; long long int llin; char* endptr; /* Set by strtoll */ int nch; errno = 0; llin = strtoll(str,...
8
by: Brian Munroe | last post by:
My example: class A(object): def __init__(self, name): self.__name = name def getName(self): return self.__name
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.