Skip to content

Instantly share code, notes, and snippets.

@triple-j
Created April 22, 2015 20:45
Show Gist options
  • Save triple-j/976182a362a9941fdeaf to your computer and use it in GitHub Desktop.
Save triple-j/976182a362a9941fdeaf to your computer and use it in GitHub Desktop.
Remove files and directories recursively.
unlinkRecursive( $filepath ) {
if ( is_file($filepath) ) {
unlink($filepath);
} elseif ( is_dir($filepath) ) {
$files = array_diff(scandir($filepath), array('.','..'));
foreach ( $files as $fpath ) {
self::unlinkRecursive($fpath);
}
rmdir($filepath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment