Thanks all for the help, I figured it out: This line was giving me grief :) doh! while( false !== ( $file == readdir( $dir ) ) ) Mark -----Original Message----- From: Jochem Maas [mailto:jochem@xxxxxxxxxxxxx] Sent: Friday, July 14, 2006 12:12 PM To: Mark Steudel Cc: php-general@xxxxxxxxxxxxx Subject: Re: Recurs Directory Delete Mark Steudel wrote: > I was hoping someone could give me a hand, I'm trying to create a delete > folders function that recursively deletes folders and files from a given > directory. Here's what I have so far, but its not working I keep getting > > Warning: rmdir(wwwroot/resources/applications/44/series/25/modules/29) > [function.rmdir]: Directory not empty in > wwwroot\common\class.directories.php on line 28 do you have the relevant permissions to unlink() the files in question? try dumping/collecting some debugging infomation a bit like this function does: /* delete everything in the $dir */ function recursiveDelete($dir) { $msgs = array( "\n"."\n".'deleting everthing in: '.$dir, "\n".'---------------------------------------------------------------' ); if ($handle = /*@*/opendir($dir)) { while (($file = readdir($handle)) !== false) { if (($file == ".") || ($file == "..")) { continue; } if (is_dir($dir.'/'.$file)) { // call self for this directory $msgs = array_merge($msgs, recursiveDelete($dir.'/'.$file)); $r = rmdir ($dir.'/'.$file); $msgs[] = "\n".'deleting dir.: '.$dir.'/'.$file.($r?' SUCCESSFUL':' FAILED'); } else { $r = unlink($dir.'/'.$file); // remove this file $msgs[] = "\n".'deleting file: '.$dir.'/'.$file.($r?' SUCCESSFUL':' FAILED'); } } /*@*/closedir($handle); return $msgs; } /* return an array of messages always - for the call array_merge() */ return array(); } > > function deleteFolders( $resource ) > { > if( is_dir( $resource ) ) > { > if( $dir = opendir( $resource ) ) > { > while( false !== ( $file == readdir( $dir ) ) ) > { > if( $file != '.' && $file != '..' ) > { > > $this->deleteFolders($resource.'/'.$file ); > } > } > closedir($dir); > rmdir($resource); > } > else > { > $this->LOG .= __LINE__ . ": Unable to open > directory\r\n"; > } > } > else > { > > if( is_file( $resource ) ) > { > unlink( $resource ); > } > else > { > $this->LOG .= __LINE__ . ": Unknown path: > $resource\r\n"; > } > } > } > > TIA, mark > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php