Logically this should work ............but it's not. I'm getting unlink failed messages......I'm trying to get rid of all files in both paths, and then get rid of the directories. I have PHP 4.1.1
<?
if ($handle = opendir('content/clients/craw')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
unlink($file);
}
}
closedir($handle);
}
if ($handle2 = opendir('content/mockups/craw')) {
while (false !== ($file2 = readdir($handle2))) {
if ($file2 != "." && $file2 != "..") {
unlink($file2);
}
}
closedir($handle2);
}
$clientfolder = "content/clients/craw";
rmdir($clientfolder);
$mockupfolder = "content/mockups/craw";
rmdir($mockupfolder);
?>
Ack! I tried this script as well and THIS does not work either. What the heck am I doing wrong? I have PHP version 4.1.1
<?
$dir_del = "content/clients/craw";
function delete_all_from_dir($Dir){
// delete everything in the directory
if($handle = @opendir($Dir)) {
while (($file = readdir($handle)) !== false) {
if($file == "." || $file == "..") { continue; }
if(is_dir($Dir.$file)){ // call self for this directory
delete_all_from_dir($Dir."/".$file."/");
chmod($Dir."/".$file, 0777);
rmdir($Dir."/".$file); echo "The Folder<b><i>$file</i></b> was removed successfuly<br>"; //remove this directory
}else {
chmod($Dir."/".$file, 0777);
unlink($Dir."/".$file); // remove this file
}
}
}
@closedir($handle);
}
delete_all_from_dir($dir_del);
?>