Hi Perry -

If you write the output to a file, instead of to the screen, then you can
simply test the number of lines in the ASCII file to see if there is a line
for a file, and based on that return either the report you have in the file
or your text string.

Hope I'm clear on this.  This is how I used to do  it in another language.
I am just beginning to learn PHP.
HTH,
/steven

Steven Olson
Alyption Media Group
104 S. Pine Street, Suite C
Sandpoint, ID 83864

[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
208.263.5886
208.304.9064 (cell)


-----Original Message-----
From: Gerenday, Perry (P.) [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 08, 2005 12:54 PM
To: [email protected]
Subject: [wdvltalk] PHP: determine if a directory is empty


I banged my head against this all day yesterday without success.
I have a file upload page for a client that also displays the files in their
directory folder using PHP.
Displaying the files is no problem. I loop through the directory like this:

  if ($handle = opendir('./ssgi/')) {
    while (false !== ($file = readdir($handle))) {
      if ($file != "." && $file != "..") {
        echo "<a href=\"ssgi/$file\">$file</a><br />\n";
      }
    }
    closedir($handle);
  }

However, when the directory is empty, I want to
display the text string, "There are no files in this folder", so the
client recognizes the folder is empty and not just failing to show their
files.
For the life of me, I can't find a way to determine if the folder is empty.
If there were a "directory size" function that would help, but all I can
find
is filesize. I've tried checking if $file == false or zero but there is
always a
dot (.) left in the folder which is used to move to the next directory
level.
Also, while using the loop method, eventually, the $file will always equal
false,
that's what brings the script to an end.
Can anybody lead me in the right direction here? What am I missing. It seems

that this should be very simple, but so far the solution is eluding me.


Thanks,
Perry Gerenday
Webmaster / Visual Communications
Visteon, Nashville Glass Plant
615.350.7656


____ � The WDVL Discussion List from WDVL.COM � ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or
use the web interface http://e-newsletters.internet.com/discussionlists.html/
       Send Your Posts To: [email protected]
To change subscription settings, add a password or view the web interface:
http://intm-dl.sparklist.com/read/?forum=wdvltalk

________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]
To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016

Please include the email address which you have been contacted with.

Reply via email to