Jump to content

Recommended Posts

Hey,

 

I know I have posted question several posts about this topic, Im just having a little but of a difficulty deleting a directory and the files at the same time. Below is the code I wrote, that deletes all the files, and the directory at the same time. I even double check the directory to make sure the files are not there, and they aren't.

 

But for some reason when I execute this code, all the files get deleted but the directory doesn't get deleted. PHP also gives me the following error message

Warning: rmdir(php_files2) [function.rmdir]: Directory not empty in /Applications/XAMPP/xamppfiles/htdocs/sandbox/delete_all_files.php on line 3

 

Below is my code. Any suggestions on how to fix this?

$dir = "php_files2";
$array_map = array_map("unlink",glob("$dir"."/*.*"));
rmdir($dir);
Link to comment
https://forums.phpfreaks.com/topic/279356-question-about-deleting-files/
Share on other sites

Are there any sub-directories in that directory also? Is so those must be deleted first as well. You'll also want to check for hidden files (files starting w/ a dot ie .htaccess). Your glob pattern will not catch those hidden files.

 

If you look at the user notes on rmdir there are numerous code samples of how to do a recursive delete of a directory, just steal one of those.

Are there any sub-directories in that directory also? Is so those must be deleted first as well. You'll also want to check for hidden files (files starting w/ a dot ie .htaccess). Your glob pattern will not catch those hidden files.

 

If you look at the user notes on rmdir there are numerous code samples of how to do a recursive delete of a directory, just steal one of those.

Thank for the reply. There is no  sub-directories. I am running on local machiene on mac OS X. Would you have any idea on how to find the hidden files? I'm not to familiar on how to use the HT access/ 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.