Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File exists??

Status
Not open for further replies.

jayne1

Technical User
Feb 5, 2002
7
GB
Hi there!

How can I set a condition that checks if a directory is empty i.e. files don't exist then take the appropriate action........pardon my ignorance!!

xxx
Jayne
 
function isempty($dirname) {
$handle=opendir($dirname);
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
return 1; //is not empty
}
return 0; //is empty
}
closedir($handle);
}

echo isempty("/home/users/mydir");

 
Thanks alot 'piti' your solution worked like a dream......just luv this site!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top