PHP遍曆、刪除檔案夾中的所有檔案

來源:互聯網
上載者:User

標籤:style   blog   color   io   os   ar   sp   檔案   div   

 1 <?php 2   header("Content-type:text/html;charset=utf-8"); 3    4   /** 5    * getDirFile 遍曆檔案夾中的所有檔案 6    * @param $path  7    */ 8   function getDirFile($path){ 9     //判斷是否是檔案夾10     if(is_dir($path)){11         //判斷是否開啟成功12         if($handle = opendir($path)){13             14             //讀取檔案15             while($file = readdir($handle)){16                 //判斷是否是檔案夾17                 if(is_dir($path.‘/‘.$file) && $file != ‘.‘ && $file != ‘..‘){18                     echo ‘檔案夾:‘.$file.‘<br/>‘;19                     getDirFile($path.‘/‘.$file);20                 } else {21                     if($file != ‘.‘ && $file != ‘..‘){22                         echo ‘檔案:‘.$file.‘<br/>‘;23                     }24                 }25             }26             27             //關閉檔案夾28             closedir($handle);29         }30     }31   }

 

 1 /** 2    * removeDir 刪除檔案夾下所有檔案 3    * @param $path 4    */ 5   function removeDir($path){ 6     //判斷是否是檔案夾 7     if(is_dir($path)){ 8         //判斷是否開啟成功 9         if($handle = opendir($path)){10             //讀取檔案11             while($file = readdir($handle)){12                 //判斷是否是檔案夾13                 if(is_dir($path.‘/‘.$file.‘/‘) && $file!=‘.‘ && $file!=‘..‘){14                     removeDir($path.‘/‘.$file.‘/‘);15                 } else {16                     if($file!=‘.‘ && $file!=‘..‘){17                         //刪除檔案18                         unlink($path.‘/‘.$file);19                     }20                 }21                 22             }23             //關閉檔案夾24             closedir($handle);25             //刪除檔案夾26             rmdir($path.‘/‘.$file.‘/‘);27         }28     }29   }

 

PHP遍曆、刪除檔案夾中的所有檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.