Skip to content

Instantly share code, notes, and snippets.

@liconti
Created April 20, 2012 06:26
Show Gist options
  • Save liconti/2426567 to your computer and use it in GitHub Desktop.
Save liconti/2426567 to your computer and use it in GitHub Desktop.
PHP recursive rmdir
<?php
function rrmdir($path){
if (is_dir($path)) {
array_map( "rrmdir", glob($path . DIRECTORY_SEPARATOR . '{,.[!.]}*', GLOB_BRACE) );
@rmdir($path);
}
else {
@unlink($path);
}
}
?>
@g-barkin
Copy link

g-barkin commented Mar 5, 2014

finally... a recursive function that will empty a directory of subdirectories and files and then delete it. StackOverflow has a slew of these that don't work. This one does. Thanks.

@keason
Copy link

keason commented Nov 24, 2017

could I call back the file , if I wrong using the command?

@jmwebservices
Copy link

This function does not recognize files whose name contains two or more leading dots. Here is a link to my fork which supports this edge case: https://gist.github.com/jmwebservices/986d9b975eb4deafcb5e2415665f8877

@ribafs
Copy link

ribafs commented Nov 4, 2019

Não se deve usar o @, mas sim tratar mesmo que seja trabalhoso.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment