Jump to content

Question about deleting files


eldan88

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/ 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.