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); } ?>
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.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With