這篇文章主要介紹了php遞歸遍歷刪除文件的方法,涉及php遍歷文件操作的相關技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了php遞歸遍歷刪除文件的方法。分享給大家供大家參考。具體如下:
這個函數稍加修改就可以變成一個遞歸文件拷貝函數
- <?php
- function mover($src,$dst) {
- $handle=opendir($src);
- // Opens source dir.
- if (!is_dir($dst)) mkdir($dst,0755);
- // Make dest dir.
- while ($file = readdir($handle)) {
- if (($file!=".") and ($file!="..")) {
- // Skips . and .. dirs
- $srcm=$src."/".$file;
- $dstm=$dst."/".$file;
- if (is_dir($srcm)) {
- // If another dir is found
- mover($srcm,$dstm);
- // calls itself - recursive WTG
- } else {
- copy($srcm,$dstm);
- unlink($srcm);
- // Is just a copy procedure is needed
- } // comment out this line
- }
- }
- closedir($handle);
- rmdir($src);
- }
- ?>
希望本文所述對大家的php程序設計有所幫助。
新聞熱點
疑難解答