• <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>

        如何删除非空目录?

        How do I remove a directory that is not empty?(如何删除非空目录?)

        <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
                  }
                  

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <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>
                              <tbody id='4nm6p'></tbody>