PHP用遞迴的方法刪除目錄

2021-06-08 21:11:38 字數 414 閱讀 1910

最近在寫乙個phpcms的檔案管理器外掛程式,在開發刪除目錄的功能的時候發現用php自帶的rmdir()函式在資料夾不為空的時候是無法刪除目錄的,所以只能從最底層開始清空目錄,這裡就用到了遞迴的方法:

/**

* 刪除目錄

* @param character $dir 目錄名稱

*/function deletedir($dir)

if(is_array($dir))

}else

while($file=$mydir->read())elseif(is_file($filename))

}$mydir->close();

chmod($dir, 0777);

rmdir($dir);

}}

遞迴刪除目錄

include stdafx.h include include include using namespace std void deletedir cstring szpath void recursiondelete cstring szpath int tmain int argc,tcha...

用遞迴列出和刪除檔案的所有目錄

遞迴 recursion 就是方法呼叫自身。對於遞迴來說,一定有乙個出口,讓遞 歸結束,只有這樣才能保證不出現死迴圈。遞迴計數器 private static int time public static void recursion 一個簡單的遞迴例項 階乘 public static int f...

php 刪除目錄

自定義的刪除函式,可以刪除檔案和遞迴刪除資料夾 function my del path 自定義my del函式,函式有乙個引數 path 當呼叫my del 函式時,我們同時要傳遞乙個路徑 例如 php rmdir path rmdir 函式刪除空的目錄 else path php 要刪除的資料夾...