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

directory, is-empty, php, removeall

Solution

Use `glob` :

if (count(glob("path/*")) === 0 ) { // empty

A nice thing about `glob` is that it doesn't return `.` and `..` directories.

Problem

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?

Original source