Back to blog

Is Empty Dir?

Php function that return true if the directory specified is empty. $bool = is_emptydir("./images"); function is_emptydir($which){ $dh=dir($which); $emptydir=true; while ($file=$dh->read())…

Php function that return true if the directory specified is empty.


$bool = is_emptydir("./images");

function is_emptydir($which){
	$dh=dir($which);
	$emptydir=true;
	while ($file=$dh->read()) {
		if(substr($file,0,1)==".") continue;
		if(!is_dir($which."/".$file)) {
			$emptydir=false;
			break;
		}
	}
	$dh->close();
	return $emptydir;
}

Canonical URL