oops - Gave you the wrong array creation information; gave you the Perl
equivalent. the PHP equiv is
array_push($array, $file);
The way that I used it was by calling the function to return the array
to where I want to print
i.e
function getDirectory($path) {
$array = array();
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))
{
if ($file != "." && $file != "..") {
array_push($array, $file);
}
}
} else {
echo "Unable to open directory! " . $path;
}
return $array;
}
--- After defining the function I would print the contents of the array
where i need them after checking if its empty
$writedata = getDirectory("../path/to/directory");
if ($writedata[0] == "") {
echo "This directory is empty";
} else {
/* print the information ( index 0 of the array is the first file, index
1 the second, etc etc ) */
}
------
hope this helps
Charles R King
( Webmaster GalatekInc.com )
Web Design / Programming. C-omputerSolutions.com
Gerenday, Perry (P.) wrote:
Hang tight everyone.
I'm not ignoring you.
I'm systematically trying all your suggestions.
So far with little success.
My continued failure is probably due to my novice understanding of PHP.
Charles: I thought the break would work too, but $file never evaluates to an
empty string,
even when I try to exclude the '.' and '..'.
The array concept looks promising. I was trying that earlier, wasn't
defining the array correctly.
My loop kept spelling out the file names one letter at a time.
Pat Richard:
Tried the counter.
Seemed like it should work but if there are no files, the output echoes
"There are no files in the folder" twice, while the loop is counting.
When there are files, I get the text string and file names. Maybe I have
the counter in the wrong place in the script. Not sure.
Steven Olson:
Your idea about sending the output to a file sounds promising.
I just have to figure out how to do that so I can test the concept.
Do you mean send it to an intermediary php page to count the lines?
Ummm, how do I count the line?
Stephen Caudill:
You suggest testing to see if there is a directory.
I don't plan on deleting the directory when no files are present.
Will this test still work even if the directory exists but is empty?
Thanks,
Perry Gerenday
Webmaster / Visual Communications
Visteon, Nashville Glass Plant
615.350.7656
-----Original Message-----
From: Galatek Webmaster [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 09, 2005 11:01 AM
To: [email protected]
Subject: Re: [wdvltalk] PHP: determine if a directory is empty
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]> dl.sparklist.com 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.
____ • 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.