code is as follows |
copy code |
/*—————————————————— */ -Delete files and directories recursively – For example: Del_dir ('../www.1111cn.net/'); Note: returned/is required – $type Force Delete directory, true Yes, false no /*—————————————————— */ function Del_dir ($dir, $type =true) { $n = 0; if (Is_dir ($dir)) { if ($dh = Opendir ($dir)) { while (($file = Readdir ($DH))!== false) { . SVN ignores SVN version control information if ($file = = '. ' or $file = = ' ... ' or $file = = '. SVN ') { Continue } if (Is_file ($dir. $file)) { Unlink ($dir. $file); $n + +; } if (Is_dir ($dir. $file)) { Del_dir ($dir. $file. /'); if ($type) { $n + +; RmDir ($dir. $file. /'); } } } } Closedir ($DH); } return $n; } |
It's easy to read. The principle is very simple, the first is to query the directory of all files or directories, if the file is deleted, if it is a directory to see whether the empty directory, if it is deleted, otherwise call this function again, on the instance of the deletion is not an empty directory function.