
1 vazo OP 如果是跳过文件名 a.php 的话,万一子文件夹也含有 a.php,就无法删除子文件夹. 现在是清空 update 前复制 a.php 到外面,清空后再复制回来. |
2 caola Aug 13, 2022 为什么一个要放这个文件到这里,不能用 nginx/apache 的 url 重写功能吗? |
3 vazo OP <? php function deldir($dir) { //删除目录下的文件 $dh = opendir($dir); while ($file = readdir($dh)) { if ($file != "." && $file != "..") { $fullpath = $dir . "/" . $file; if (!is_dir($fullpath)) { if (fullpath == "update/index.php") { //增加一个条件排除 update 下的 index.php } else { unlink($fullpath); } else { deldir($fullpath); } } } } closedir($dh); //删除文件夹 if (rmdir($dir)) { return true; } else { return false; } } deldir('update') //需要清空操作的文件夹 ?> |
4 vazo OP 跑了一下应该是 ok 了. |
6 wxf666 Aug 13, 2022 『 find . -path ./update/a.php -o -delete 』? |
8 vazo OP #3 代码有误,更正如下 <? function deldir($dir) { //删除目录下的文件 $dh = opendir($dir); while ($file = readdir($dh)) { if ($file != "." && $file != "..") { $fullpath = $dir . "/" . $file; if (!is_dir($fullpath)) { if ($fullpath == "update/a.php") { //增加一个条件排除 update 下的 a.php } else { unlink($fullpath); } } else { deldir($fullpath); } } } closedir($dh); //删除当前文件夹 if (rmdir($dir)) { return true; } else { return false; } } deldir('update') //需要清空操作的文件夹 ?> |
9 realpg PRO 把 a.php 加入 git git reset --hard |