Created
January 29, 2010 16:32
-
-
Save saltybeagle/289865 to your computer and use it in GitHub Desktop.
PHP recursive delete with closure
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
<?php | |
// recursive delete function | |
$unlink = function($path) use (&$unlink) { | |
if (is_file($path)){ | |
return unlink($path); | |
} | |
if (is_dir($path)) { | |
$files = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*'); | |
foreach($files as $file){ | |
$unlink($file); | |
} | |
return rmdir($path); | |
} | |
}; | |
$unlink('/Thedir'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment