Created
March 19, 2014 20:21
-
-
Save maxout/9650366 to your computer and use it in GitHub Desktop.
unlink all Files and Folders in current folder
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
$files = glob("*"); | |
foreach($files as $file){ | |
rrmdir($file); | |
} | |
function rrmdir($dir) | |
{ | |
if (is_dir($dir)) // ensures that we actually have a directory | |
{ | |
$objects = scandir($dir); // gets all files and folders inside | |
foreach ($objects as $object) | |
{ | |
if ($object != '.' && $object != '..') | |
{ | |
if (is_dir($dir . '/' . $object)) | |
{ | |
// if we find a directory, do a recursive call | |
rrmdir($dir . '/' . $object); | |
} | |
else | |
{ | |
// if we find a file, simply delete it | |
unlink($dir . '/' . $object); | |
} | |
} | |
} | |
// the original directory is now empty, so delete it | |
rmdir($dir); | |
}else{ | |
unlink($dir); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment