Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: What is the best and easiest way to check if directory is empty or not [closed]

Tags:

People also ask

How do you check if the folder is empty or not in PHP?

Your answer php $pid = basename($_GET["prodref"]); //let's sanitize it a bit $dir = "/assets/$pid/v"; if (is_dir_empty($dir)) { echo "the folder is empty"; }else{ echo "the folder is NOT empty"; } function is_dir_empty($dir) { if (! is_readable($dir)) return NULL; return (count(scandir($dir)) == 2); } ?>

How do you check if a folder contains a file in PHP?

The file_exists() function in PHP is an inbuilt function which is used to check whether a file or directory exists or not. The path of the file or directory you want to check is passed as a parameter to the file_exists() function which returns True on success and False on failure.

Is PHP a directory?

The is_dir() function in PHP used to check whether the specified file is a directory or not. The name of the file is sent as a parameter to the is_dir() function and it returns True if the file is a directory else it returns False.

How do I check if a directory is empty in C++?

We can call IsEmpty to check whether a given directory is empty. An empty directory is considered to have no files or other directories in it. IsEmpty returns true if the directory is empty; false otherwise.


I got a root directory with 100s of dynamically generated folders. As time goes some of these folders will need to be extirpated from system on the condition that this(ese) directories(s) must be empty. What would be the best shortest, easiest and/or most effective way to achieve that?