-1 |
|
<?PHP
// loc1 is the path on the computer to the base directory that may be moved
define('loc1', 'C:/Program Files/Apache Group/Apache/htdocs', true);
// use this format:
$dir = '[reletive path]';
if(remdir($dir))
rmdir($dir);
else
echo 'There was an error.';
// this function deletes all files and sub directories directories in a directory
// bool remdir( str 'directory path' )
function remdir($dir){
if(!isset($GLOBALS['remerror']))
$GLOBALS['remerror'] = false;
if($handle = opendir(loc1 . $dir)){ // if the folder exploration is sucsessful, continue
while (false !== ($file = readdir($handle))){ // as long as storing the next file to $file is successful, continue
$path = $dir . '/' . $file;
if(is_file(loc1 . $path)){
if(!unlink(loc1 . $path)){
echo '<u><font color="red">"' . $path . '" could not be deleted. This may be due to a permissions problem.</u><br>Directory cannot be deleted until all files are deleted.</font><br>';
$GLOBALS['remerror'] = true;
return false;
}
} else
if(is_dir(loc1 . $path) && substr($file, 0, 1) != '.'){
remdir($path);
@rmdir(loc1 . $path);
}
}
closedir($handle); // close the folder exploration
}
if(!$GLOBALS['remerror']) // if no errors occured, delete the now empty directory.
if(!rmdir(loc1 . $dir)){
echo '<b><font color="red">Could not remove directory "' . $dir . '". This may be due to a permissions problem.</font></b><br>';
return false;
} else
return true;
return false;
} // end of remdir()
?>
<?PHP // loc1 is the path on the computer to the base directory that may be moved define('loc1', 'C:/Program Files/Apache Group/Apache/htdocs', true); // use this format: $dir = '[reletive path]'; if(remdir($dir)) else echo 'There was an error.'; // this function deletes all files and sub directories directories in a directory // bool remdir( str 'directory path' ) function remdir($dir){ if(!isset($GLOBALS['remerror'])) $GLOBALS['remerror'] = false; if($handle = opendir(loc1 . $dir)){ // if the folder exploration is sucsessful, continue while (false !== ($file = readdir($handle))){ // as long as storing the next file to $file is successful, continue $path = $dir . '/' . $file; echo '<u><font color="red">"' . $path . '" could not be deleted. This may be due to a permissions problem.</u><br>Directory cannot be deleted until all files are deleted.</font><br>'; $GLOBALS['remerror'] = true; return false; } } else remdir($path); } } closedir($handle); // close the folder exploration } if(!$GLOBALS['remerror']) // if no errors occured, delete the now empty directory. echo '<b><font color="red">Could not remove directory "' . $dir . '". This may be due to a permissions problem.</font></b><br>'; return false; } else return true; return false; } // end of remdir() ?>
PHP.net: rmDir |