• <bdo id='wVI20'></bdo><ul id='wVI20'></ul>

      <small id='wVI20'></small><noframes id='wVI20'>

      <i id='wVI20'><tr id='wVI20'><dt id='wVI20'><q id='wVI20'><span id='wVI20'><b id='wVI20'><form id='wVI20'><ins id='wVI20'></ins><ul id='wVI20'></ul><sub id='wVI20'></sub></form><legend id='wVI20'></legend><bdo id='wVI20'><pre id='wVI20'><center id='wVI20'></center></pre></bdo></b><th id='wVI20'></th></span></q></dt></tr></i><div id='wVI20'><tfoot id='wVI20'></tfoot><dl id='wVI20'><fieldset id='wVI20'></fieldset></dl></div>
      <legend id='wVI20'><style id='wVI20'><dir id='wVI20'><q id='wVI20'></q></dir></style></legend>

        <tfoot id='wVI20'></tfoot>

        如何删除非空目录?

        时间:2023-07-15

        <legend id='4OOzo'><style id='4OOzo'><dir id='4OOzo'><q id='4OOzo'></q></dir></style></legend>
            <tbody id='4OOzo'></tbody>
            <bdo id='4OOzo'></bdo><ul id='4OOzo'></ul>

            • <tfoot id='4OOzo'></tfoot>

                • <small id='4OOzo'></small><noframes id='4OOzo'>

                  <i id='4OOzo'><tr id='4OOzo'><dt id='4OOzo'><q id='4OOzo'><span id='4OOzo'><b id='4OOzo'><form id='4OOzo'><ins id='4OOzo'></ins><ul id='4OOzo'></ul><sub id='4OOzo'></sub></form><legend id='4OOzo'></legend><bdo id='4OOzo'><pre id='4OOzo'><center id='4OOzo'></center></pre></bdo></b><th id='4OOzo'></th></span></q></dt></tr></i><div id='4OOzo'><tfoot id='4OOzo'></tfoot><dl id='4OOzo'><fieldset id='4OOzo'></fieldset></dl></div>
                  本文介绍了如何删除非空目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 rmdir 删除一个目录,但我收到了目录非空"消息,因为其中仍有文件.

                  I am trying to remove a directory with rmdir, but I received the 'Directory not empty' message, because it still has files in it.

                  我可以使用什么函数来删除包含所有文件的目录?

                  What function can I use to remove a directory with all the files in it as well?

                  推荐答案

                  没有内置函数可以做到这一点,但请参阅 http://us3.php.net/rmdir.许多评论者发布了他们自己的递归目录删除功能.您可以从中挑选.

                  There is no built-in function to do this, but see the comments at the bottom of http://us3.php.net/rmdir. A number of commenters posted their own recursive directory deletion functions. You can take your pick from those.

                  这是一个看起来不错的:

                  function deleteDirectory($dir) {
                      if (!file_exists($dir)) {
                          return true;
                      }
                  
                      if (!is_dir($dir)) {
                          return unlink($dir);
                      }
                  
                      foreach (scandir($dir) as $item) {
                          if ($item == '.' || $item == '..') {
                              continue;
                          }
                  
                          if (!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
                              return false;
                          }
                  
                      }
                  
                      return rmdir($dir);
                  }
                  

                  如果您想保持简单,您可以只调用 rm -rf.这确实使您的脚本仅适用于 UNIX,因此请注意这一点.如果你走那条路,我会尝试这样的事情:

                  You could just invoke rm -rf if you want to keep things simple. That does make your script UNIX-only, so beware of that. If you go that route I would try something like:

                  function deleteDirectory($dir) {
                      system('rm -rf -- ' . escapeshellarg($dir), $retval);
                      return $retval == 0; // UNIX commands return zero on success
                  }
                  

                  这篇关于如何删除非空目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 scandir() 在目录中查找文件夹 (PHP) 下一篇:getcwd() 和 dirname(__FILE__) 之间的区别?我应该使用哪个?

                  相关文章

                  <legend id='4nm6p'><style id='4nm6p'><dir id='4nm6p'><q id='4nm6p'></q></dir></style></legend>
                  <i id='4nm6p'><tr id='4nm6p'><dt id='4nm6p'><q id='4nm6p'><span id='4nm6p'><b id='4nm6p'><form id='4nm6p'><ins id='4nm6p'></ins><ul id='4nm6p'></ul><sub id='4nm6p'></sub></form><legend id='4nm6p'></legend><bdo id='4nm6p'><pre id='4nm6p'><center id='4nm6p'></center></pre></bdo></b><th id='4nm6p'></th></span></q></dt></tr></i><div id='4nm6p'><tfoot id='4nm6p'></tfoot><dl id='4nm6p'><fieldset id='4nm6p'></fieldset></dl></div>
                • <tfoot id='4nm6p'></tfoot>

                    1. <small id='4nm6p'></small><noframes id='4nm6p'>

                        <bdo id='4nm6p'></bdo><ul id='4nm6p'></ul>