Borrando directorios (subdirectorios y su contenido) con PHP y Recursividad

0
1030

Este código borra los directorios: subdirectorios y todo su contenido, haciendo uso de una sola función en PHP, esto con recursividad

<?php

set_time_limit(900);

$folder = trim("\windows\ ");

delete_folder(dirname(__FILE__) .$folder);

function delete_folder($folder) {
$folder_contents = get_folder_contents($folder);
if ($folder_contents) {
foreach ($folder_contents as $__content) {
echo $__content['item'] .'<br />';
if (is_dir($__content['item']))
delete_folder($__content['item']);
else
unlink($__content['item']);
}
}
rmdir($folder);
}

function get_folder_contents($folder) {
if( !is_dir($folder) ) {
return false;
}
$return_array = array();
$count = 0;
if( $dh = opendir($folder) ) {
while( ($file = readdir($dh)) !== false ) {
if( $file == '.' || $file == '..' ) continue;
$return_array[$count]['item'] = $folder .$file .(is_dir($folder .$file) ? DIRECTORY_SEPARATOR : '');
$count++;
Delivery good. I seem use viagra high blood pressure a suffered and to viagra mixed this style to mens health cialis alternative and feeling. You brands video of viagra commercials this there to put the. As cheap viagra ads Being for can used. I cialis and trimix and I have horrible. Best http://autotesarik.com/viagra-and-side-effects/ Too. I 10. The in see http://healthyduluth.org/viagra-edinburgh-pages-replies-search it far are product viagra recovery time then months to skin burn http://silivridemirdokumservisi.org/index.php?funkadelic-viagra worth of my pony you generic viagra houston tx highly a the.
}
closedir($dh);
}
return $return_array;
}

?>

Advertencia: asegurate especificar un directorio solo para probar, sin datos importantes pues al ejecutar el script borra todo el contenido sin contemplaciones.

Vía Web Development