Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active January 12, 2023 08:03
Show Gist options
  • Save vielhuber/4287bb0575ce0f5ea732 to your computer and use it in GitHub Desktop.
Save vielhuber/4287bb0575ce0f5ea732 to your computer and use it in GitHub Desktop.
script to find empty folders (recursively) and place an empty file in it #php
<?php
function EmptySubFolders($path) {
$empty = true;
foreach(glob($path.DIRECTORY_SEPARATOR."*") as $file) {
if (is_dir($file)) {
if (!EmptySubFolders($file)) {
$empty = false;
}
}
else {
$empty = false;
}
}
if($empty) {
touch($path."/empty-folder");
}
return $empty;
}
EmptySubFolders('.');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment