Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

recursive function to delete directories

Tue Oct 28, 2008 1:42 pm

Code:
   

<?php

   
function delete_directory($dir) {
      if (
$dh = @opendir($dir)) {
          while ((
$file = readdir ($dh)) != false) {
             if ((
$file == ".") || ($file == "..")) continue;
                if (
is_dir($dir . '/' . $file))
                   
delete_directory($dir . '/' . $file);
                else
                   
unlink($dir . '/' . $file);
          }
          @
closedir($dh);
          
rmdir($dir);
      }
   }
$dir = "./fakeDir";
delete_directory($dir);
?>




Post a reply
  Related Posts  to : recursive function to delete directories
 problem, recursive function using array_merge()     -  
 problem, recursive function using array_merge()     -  
 Compare directories     -  
 count the number of files in directory & its sub directories     -  
 Feature selection: Statistical and Recursive examples     -  
 recursive string reversal- reverse string     -  
 Delete directory in php     -  
 DELETE Commands     -  
 delete file in asp     -  
 Delete file     -  

Topic Tags

PHP Files and I/O, PHP Functions