Posted By

fedek6 on 04/22/14


Tagged

delete rm recursive contents


Versions (?)

Delete all files and folders in specified paths


 / Published in: PHP
 

Delete all files and directories in specified path recursively.

  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  

You need to login to post a comment.