Created
September 12, 2014 17:11
-
-
Save SDKiller/059f2729f51d18979bf3 to your computer and use it in GitHub Desktop.
FileHelper override
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function removeDirectory($dir, $options = []) | |
{ | |
if (!is_dir($dir)) { | |
echo 'Path is not a directory or not exists: ' . $dir . PHP_EOL; | |
return; | |
} | |
if (!is_link($dir) || isset($options['traverseSymlinks']) && $options['traverseSymlinks']) { | |
if (!($handle = opendir($dir))) { | |
echo 'Failed to open: ' . $dir . PHP_EOL; | |
return; | |
} | |
while (($file = readdir($handle)) !== false) { | |
if ($file === '.' || $file === '..') { | |
continue; | |
} | |
$path = $dir . DIRECTORY_SEPARATOR . $file; | |
if (is_dir($path)) { | |
static::removeDirectory($path, $options); | |
} else { | |
if (!unlink($path)) { | |
echo 'Failed to delete file: ' . $dir . PHP_EOL; | |
} | |
} | |
} | |
closedir($handle); | |
} | |
if (is_link($dir)) { | |
if (!unlink($dir)) { | |
echo 'Failed to delete file: ' . $dir . PHP_EOL; | |
} | |
} else { | |
if (!rmdir($dir)) { | |
echo 'Failed to delete folder: ' . $dir . PHP_EOL; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment