Possible Duplicate:
How do I recursively delete a directory and its entire contents (files+sub dirs) in PHP?
How do I recursively delete a directory and its entire contents (files+sub dirs) in PHP?
This doesn't delete folders recursively; it only works if the folder has only regular files in it, all of which have file extensions. – mgnb Jul 9 '15 at 2:04. If no recursion is needed this is the best and simpliest answer so far.
I need to recursively delete a directory and subdirectories that aren't empty. I can't find any useful class or function to solve this problem.
In advance thanks for your answers.
Community♦
Lukáš JeličLukáš Jelič22433 gold badges66 silver badges1919 bronze badges
marked as duplicate by Adam Zalcman, Oliver Charlesworth, Lion, alex, GravitonMar 19 '12 at 2:14
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
![Recursively Recursively](/uploads/1/2/5/8/125830306/929827400.png)
3 Answers
From the first comment in the official documentation.
Edited rmdir to rrmdir to correct typo from obvious intent to create recursive function.
lorenzo-slorenzo-s11.7k1212 gold badges3737 silver badges7474 bronze badges
Something like this should do it...
This deletes all child files and folders and then removes the top level folder passed to it.
![Powershell delete folder contents Powershell delete folder contents](/uploads/1/2/5/8/125830306/925695684.png)
It could do with some error checking such as testing the path supplied is a directory and making sure each deletion was successful.
alexalex351k174174 gold badges786786 silver badges920920 bronze badges
To recursively delete a directory use this:
Only tested on unix.
d_inevitabled_inevitable