Codice PHP:
/**
* remove_empty_subdirectories()
*
* Removes empty folders inside the given path.
* Does not touch files and folders containing files.
*
* @param mixed $path
* @return void
*/
function remove_empty_subdirectories($path)
{
// If the path has a slash at the end we remove it here
if(substr($path, -1, 1) == '/')
{
$path = substr($path, 0, -1);
}
if(!is_dir($path))
{
// If the path is not a directory
return;
}
// List directories
$values = @glob($path . '/*', GLOB_ONLYDIR);
if(!is_array($values))
{
return;
}
foreach($values AS $value)
{
// Recurse
remove_empty_subdirectories($value);
// Attempt to delete directory
@rmdir($value);
}
}
Segnalibri