eldan88 Posted June 19, 2013 Share Posted June 19, 2013 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); Quote Link to comment https://forums.phpfreaks.com/topic/279356-question-about-deleting-files/ Share on other sites More sharing options...
kicken Posted June 19, 2013 Share Posted June 19, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/279356-question-about-deleting-files/#findComment-1436859 Share on other sites More sharing options...
eldan88 Posted June 19, 2013 Author Share Posted June 19, 2013 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/ Quote Link to comment https://forums.phpfreaks.com/topic/279356-question-about-deleting-files/#findComment-1436864 Share on other sites More sharing options...
kicken Posted June 19, 2013 Share Posted June 19, 2013 On linux/unix you'd run ls -al from a terminal. My understanding is that OS X is similar so give that a try. Quote Link to comment https://forums.phpfreaks.com/topic/279356-question-about-deleting-files/#findComment-1436865 Share on other sites More sharing options...
eldan88 Posted June 19, 2013 Author Share Posted June 19, 2013 On linux/unix you'd run ls -al from a terminal. My understanding is that OS X is similar so give that a try. Okay Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/279356-question-about-deleting-files/#findComment-1436866 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.