Delete all files and folders in specified paths


/ Published in: PHP
Save to your folder(s)

Delete all files and directories in specified path recursively.


Copy this code and paste it in your HTML
  1. // delete all folder contents recursive
  2. function delDirContents($dir) {
  3. $files = glob($dir . '/*', GLOB_MARK);
  4.  
  5. foreach($files as $file)
  6. {
  7. if (is_dir($file)) {
  8. delDirContents($file);
  9. } else {
  10. unlink($file);
  11. }
  12. }
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.