Is Empty Dir?

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

Novembre 9, 2009

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;
}

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Recommended

ASP Function to count files in a folder

This ASP function counts files of a specified extension inside a folder: this is done by creating a file system…

Febbraio 9, 2010

Recursive remove directory (RMDIR) in PHP

This small php function is a recursive remove directory that remove non empty dirs recursively. It enters every directory, removes…

Febbraio 2, 2010

Calculate dir size recursively with PHP (and count files)

This small PHP function lets you calculate the dir size entering each sub dir and making the sum of the…

Febbraio 1, 2010

Venn’s diagram applied to web agency life and software development

Thoughts about Venn's diagram and making software.

Giugno 13, 2024

The Quantcast CMP broke my sites

A javascript error in CMP blocks my site.

Maggio 19, 2023