Skip to content

Instantly share code, notes, and snippets.

@zerobugs-oficial
Created June 18, 2020 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerobugs-oficial/f018c043bf8062aabbe9b5e6234c1c09 to your computer and use it in GitHub Desktop.
Save zerobugs-oficial/f018c043bf8062aabbe9b5e6234c1c09 to your computer and use it in GitHub Desktop.
Deletar um diretório com arquivos e subdiretórios usando PHP
<?php
function deletar($pasta){
$iterator = new RecursiveDirectoryIterator($pasta,FilesystemIterator::SKIP_DOTS);
$rec_iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST);
foreach($rec_iterator as $file){
$file->isFile() ? unlink($file->getPathname()) : rmdir($file->getPathname());
}
rmdir($pasta);
}
// EXEMPLO DE UTILIZACAO
deletar('nomeDaPasta');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment