Friday, October 26, 2018

Delete tree view file and folder


<?php

function is_dir_empty($dir) {
  if (!is_readable($dir)) return NULL;
  $handle = opendir($dir);
  while (false !== ($entry = readdir($handle))) {
    if ($entry != "." && $entry != "..") {
      return FALSE;
    }
  }
  return TRUE;
}



function deletFunction($dir){
   
   
    if ($handle = opendir($dir)) {
        while (false !== ($entry = readdir($handle))) {
            if ($entry != "." && $entry != "..") {
               
                $pathDF=$dir.'/'.$entry;
               
               
                if(is_file($pathDF)){
                echo $pathDF;
                echo "</br>this is file"."</br>";
                unlink($pathDF);
                }
               
               
               
                if(is_dir($pathDF)){
                    echo $pathDF;
                   
                    if(is_dir_empty($pathDF)) {
                       
                        rmdir($pathDF);
                        echo "</br>---empty Dir"."</br>";
                    }else{
                        echo "</br>------Not Empty Dir</br>";
                        deletFunction($pathDF);
                    }
                   
                   
                    //deletFunction($pathDF);
                    //    break;
                }
                //
            }
        }
        closedir($handle);
    }
}
    deletFunction('abc');
?>

No comments:

Post a Comment