just add a line to check for an empty string in $file and break the loop after printing the message you want to print.

i.e.

 $continue = true;      /* Set a BOOLEAN variable to keep the loop going as 
long as there are files */
 if ($handle = opendir('./ssgi/')) {
   while (false !== ($file = readdir($handle))) {
     if ($file != "." && $file != "..") {
       echo "<a href=\"ssgi/$file\">$file</a><br />\n";
        $continue = true;
     } elseif ($file == "") {
        echo "There are no files in this folder";
        $continue = false;
     }
     if ($continue == false) { break; }
   }                                            
   closedir($handle);
 }

This should work well ( I use a similar system on one of my projects )

another option is to push the results into an array ( push(@array, $file); ) and check to see if the first array item ( $array[0] ) is empty or not when printing the information this requires using the function to return the array and printing it out with a seperate block of code.

Charles R King
( Webmaster GalatekInc.com )
Web Design / Programming. C-omputerSolutions.com


Gerenday, Perry (P.) wrote:

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.






____ • 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: unknown lmsubst tag argument: ''
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