问题标签 [rmdir]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
157 浏览

php - 删除目录和里面的目录

我想删除一个目录及其所有子目录。

不幸的是,这不起作用。我收到 2 个错误,说目录不为空。如果我刷新,只有 1 个错误,如果我再次刷新,没有更多的错误。


发生的情况是脚本尝试在前一个任务执行之前删除父目录,这使得文件夹非空。我该如何解决?

0 投票
1 回答
703 浏览

php - PHP递归删除空父目录

问题背景

我有一个多媒体网络应用程序,用户可以在其中保存和删除文件。保存的文件用于各种应用程序范围的功能。

当文件被保存时,它们被放在目录树的深处(通常是 6 到 9 个文件夹深)。这些文件被放置在如此深的层次上,以确保管理员/超级用户在查看文件结构时很容易区分它们,与现有的手动系统相匹配。

例如,
“UploadedAssets”是根目录,可以包含以下文件夹结构:
\ith\sp\cookery\ckpe\interactives\timestep\blahblah\item1\image01.png
\ith\sp\cookery\ckpe\interactives\timestep\ blah_only\item1\image02.png
\ith\sp\cookery\ckpe\interactives\timestep\blah_only\item2\image03.png
\ith\sp\cookery\abcd\interactives\timestep\blahblah\item1\image66.png

  1. 前 5 个名称是用户可选择的(从动态下拉菜单中),每个名称大约有 20-25 个选项。
  2. 最后 3 个取决于任何用户输入(例如类别、标题等)。这是使用文本输入字段从用户那里收到的。这些可以是 1 个或最多 4 个目录。
  3. 最后一个目录“item1”可以有一个或多个文件没有子目录
  4. 每个目录除了最后一个(item1)可以有其他子目录
  5. 当我删除/删除文件时,显然程序知道文件位置的完整路径。

由于可能的目录名称选项的数量,即使在测试阶段,根“UploadedAssets”目录已经爆炸,并且有大量未使用的空目录和死分支。


我的问题是

一旦用户从目录中删除了一个/多个文件(例如item1中的image01.png),

  1. 如何从已删除的文件中向上遍历树(仅指向直接父节点)并删除父节点(如果父节点为空)。
  2. 删除时,如果其中一个目录有其他子/文件,则不要删除该目录并完成该过程。
  3. 在预定义的根目录处删除停止或
  4. 向上n级目录后停止

例如在上面给出的示例目录结构中,
如果用户删除image01.png那么它应该删除item1blahblah目录
如果用户删除image02.png那么它应该只删除它的父item1目录
如果用户删除image66.png那么它应该删除所有父目录包括abcd 的目录


我的尝试/研究

我知道如何使用 php 删除单个目录rmdir删除单个目录。但是无法考虑如何递归地使用它来解决我的问题。

我试图了解以下内容,但我不知道这些内容是否适合我的问题 PHP:取消链接目录中的所有文件,然后删除该目录

删除文件然后目录

http://php.net/manual/en/function.glob.php

https://stackoverflow.com/a/4490706/2337895

0 投票
2 回答
1006 浏览

windows - Windows:删除多个子文件夹中的通用文件夹

有没有办法做到这一点?我有这样的文件夹结构:

我想删除所有“文件夹/”以及它们的所有内容。我的第一个猜测是

但在 *. 在过去的几天里,这已经出现了几次,所以我想我会得到比进入每个文件夹更有效的方法,因为那并不有趣。

0 投票
1 回答
1562 浏览

java - Android 无法执行 rm -r

我有一个在 SD 卡上有目录的应用程序。应用程序将笔记保存在新的子目录中。我想使用 shell 命令“rm -r”删除整个子目录,但应用程序抛出异常:

04-02 23:14:23.410: W/System.err(14891): java.io.IOException: Error running exec(). Command: [cd, /mnt/sdcard/mynote, &&, rm, -r, aaa] Working Directory: null Environment: null

谁能帮我?

0 投票
1 回答
783 浏览

c - 为什么rmdir在程序退出后删除文件夹?(在Win7中使用Dev C++)


我正在尝试编写一个名为 myremoved 的函数。我希望它删除一个非空文件夹。
但是现在我遇到了一个问题,当我使用函数(下面的代码)删除所有文件和文件夹时,“rmdir”表示文件夹已删除,但是当我打开 Windows 资源管理器时,我看到已被报告删除的文件夹仍然存在(我尝试访问,但被拒绝。)。

这是函数“myremove”代码:

0 投票
2 回答
3452 浏览

php - rmdir no such file directory error although directory exist

If use this function to remove a directory + all files inside.

But whenever I do this, I get this error message:

Warning: rmdir(directory/12) [function.rmdir]: No such file or directory in delete_files.php

"directory/12" is the correct name of the directory I wanted to delete. I don't understand why it says that it does not exist because it does! Weirdly though, even though I got the error message, the directory DID get deleted.

So I added a line of code print_n($files); before the for-loop and it game me two arrays -- one containing the directory ("directory/12") and the other containing all the files of the directory ("directory/12/01.gif", "directory/12/02.gif" etc). So I figured the directory must have gotten deleted in the for-loop and removed the line rmdir($target) and tried it again. This time, all the files within the directory got deleted but the directory itself remained.

So apparently, rmdir DOES indeed remove the directory correctly. But then, why does it give me the error message beforehand that it doesn't exist?

0 投票
1 回答
2088 浏览

perl - 使用 perl 脚本递归删除文件

我想在 perl 脚本中仅使用“rmdir”删除目录中的所有文件。我正在尝试先清理目录,然后再尝试写入文件。我知道我可以只使用 rmtree ("目录路径"); 但我无法将其用于 FTP 服务器(使用 Net::FTP;)。和 rmdir 寻找空目录。我试过“remove_tree”和“rm -rf”。我确实具有对服务器的读/写访问权限,但我无法删除文件。

Perl 脚本:

0 投票
0 回答
306 浏览

php - 我无法使用我的 php 脚本删除主机中的文件?

我使用此代码删除主机脚本中的文件和文件夹已成功删除文件夹,但脚本无法删除主机中的文件,谁能解释我的错误或任何其他提示?
这是我的代码:

文件夹 755 和文件的主机默认权限是 644。我将文件权限更改为任何其他权限,但仍然无法正常工作。

0 投票
1 回答
20 浏览

centos - 如何删除此符号链接

我创建了一个符号链接,并尝试使用 rm /WebRoot它删除它,但我收到错误Is a directory,但如果我尝试rmdir /WebRoot我收到错误Not a directory

有谁知道这里发生了什么?

在此处输入图像描述

0 投票
1 回答
250 浏览

nsis - 在文件管理器中打开 dir 时的 NSIS RMDi

我有一个卸载程序,其中使用 RMDir 和 RMDir /r 删除了目录。在调试时,我意识到如果在 Windows 资源管理器等文件管理器中打开目录,这两个功能都不起作用。目录没有被删除。

为什么会发生这种情况。我能做些什么呢?