Jump to content

rmdir()


astralaaron
 Share

Recommended Posts

"Warning: rmdir(container/a479a5d4b31979) [function.rmdir]: Directory not empty in C:\wamp\www\siteb\admin\pictures\adm_del_gal_s3.php on line 82Container not deleted"I get this error when trying to rmdir() that has photos in it, i thought it would delete all the photos for me but i guess not...is there some easy way to delete all the photos? or do I have to loop an unlink() and delete them all seperately?

Link to comment
Share on other sites

Yeah, the only way to do it is to delete all of the files first, most people generally like to create a function of their own for this kind of thing. If you'd like i could give you one, but the way you're doing it is pretty much the same way I would.

Link to comment
Share on other sites

The function should be recursive. If you find a subdirectory inside the folder then you also need to delete all of the files and folders in that as well, even if there are 100 levels of folders deep. A recursive function will do that.

function delete_dir($dir){  if (!is_dir($dir))	return false;  $info = scandir($dir);  foreach ($info as $chunk)  {	if ($chunk != "." && $chunk != "..")	{	  $chunk = $dir . DIRECTORY_SEPARATOR . $chunk;	  if (is_dir($chunk))		delete_dir($chunk);	  else		unlink($chunk);	}  }  rmdir($dir);  return true;}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...