Skip to content

Instantly share code, notes, and snippets.

@hadrienblanc
Created January 9, 2017 19:36
Show Gist options
  • Save hadrienblanc/93889e0a510a4ef6ee969ff1dd3f6bd3 to your computer and use it in GitHub Desktop.
Save hadrienblanc/93889e0a510a4ef6ee969ff1dd3f6bd3 to your computer and use it in GitHub Desktop.
<?php
/*
*
*/
$folder_to_action = "Report-PAR-3-1";
function recursiveRemoveDirectory($directory)
{
foreach(scandir($directory) as $file)
{
if(is_dir($directory . '/' . $file) && $file != '.' && $file != '..') {
recursiveRemoveDirectory($file);
} elseif ($file != '.' && $file != '..') {
unlink($directory . '/' . $file);
}
}
rmdir($directory);
}
$list = scandir($folder_to_action);
for ($i = 0; isset($list[$i]) ; $i++)
{
if ($list[$i] != '.' && $list[$i] != '..' && $list[$i] != '.DS_Store')
{
$sub_list = scandir($folder_to_action. "/" . $list[$i] . "");
echo count($sub_list) . " ";
if (count($sub_list) == 3)
{
recursiveRemoveDirectory($folder_to_action . "/" . $list[$i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment