windows deltree 发生了什么,它的替代品是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/338895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What ever happened to deltree, and what's its replacement?
提问by David Koelle
In earlier versions of MS-DOS - I want to say version 7, but I could be wrong - there was a deltree
command, which recursively deleted all subdirectories and files from a given path.
在早期版本的 MS-DOS 中——我想说版本 7,但我可能错了——有一个deltree
命令,它递归地删除给定路径中的所有子目录和文件。
deltree
no longer exists, but del
didn't seem to inherit the ability to delete a tree. del /s
deletes files, but not folders.
deltree
不再存在,但del
似乎没有继承删除树的能力。del /s
删除文件,但不删除文件夹。
How to you easily (i.e., in one command) delete a tree from a batch file?
如何轻松地(即,在一个命令中)从批处理文件中删除一棵树?
回答by Synetech
As others have mentioned, the rd
command has the /s
switch to recursively remove sub-directories. You can combine it with the /q
switch to forcibly delete a sub-directory (and its contents) without prompting as so
正如其他人所提到的,该rd
命令具有/s
递归删除子目录的开关。可以结合/q
开关强行删除子目录(及其内容)而不提示
rd /s /q c:\foobar
What everybody is missing is that rd
is notan exact replacement for deltree
as seemingly (almost) every page returned by Googling for windows deltree
would have you believe. The deltree
command worked for both directories and files, making it a single convenient, all-purpose deletion command. That is both of the following are valid:
每个人都缺少的是,它rd
并不能完全替代Google 搜索返回的deltree
看似(几乎)每个页面windows deltree
会让您相信。该deltree
命令适用于目录和文件,使其成为一个方便的通用删除命令。即以下两项均有效:
deltree /y c:\foobar
deltree /y c:\baz.txt
However rd
(not surprisingly) only works for directories. As such only the first of these commands is valid while the second gives and error and leaves the file un-deleted:
但是rd
(不足为奇)仅适用于目录。因此,只有这些命令中的第一个是有效的,而第二个给出和错误并使文件未删除:
rd /s /q c:\foobar
rd /s /q c:\baz.txt
Further, the del
command only works for files, not directories, so only the second command is valid while the first gives an error:
此外,该del
命令仅适用于文件,而不适用于目录,因此只有第二个命令有效,而第一个命令会出错:
del /f /q c:\foobar
del /f /q c:\baz.txt
There is no built-in way to delete files and directories as could be done with deltree
. Using rd
and del
individually is inconvenient at best because it requires distinguishing whether a file-system object (file-/folder-name) is a file or directory which is not always possible or practical.
没有像deltree
. 单独使用rd
和del
充其量是不方便的,因为它需要区分文件系统对象(文件/文件夹名称)是文件还是目录,这并不总是可行或实用。
You can copy the deltree
command from a previous OS, however it will only work on 32-bit versions of Windows since it is a 16-bit DOS command (even in Windows 9x).
您可以deltree
从以前的操作系统复制该命令,但它只能在 32 位版本的 Windows 上运行,因为它是一个 16 位 DOS 命令(即使在 Windows 9x 中)。
Another option is to create a batch-file that calls both del
and rd
; something like this:
另一种选择是创建一个批处理文件,同时调用del
和rd
; 像这样:
::deltree.bat
@echo off
rd %* 2> nul
del %* 2> nul
You would call it as so:
你会这样称呼它:
deltree.bat /s /q /f c:\foobar
deltree.bat /s /q /f c:\baz.txt
This calls both rd
and del
, passing in the arguments and redirecting the output to nul
to avoid the error that one of them will invariably emit.
这会调用rd
and del
,传入参数并重定向输出nul
以避免其中之一总是会发出错误。
You will probably want to customize the behavior to accomodate or simplify parameters or allow error messages, but even so, it is not ideal and not a direct replacement for deltree
.
您可能希望自定义行为以适应或简化参数或允许错误消息,但即便如此,它也不理想,也不能直接替代deltree
.
An alternative is to get a third-party tool, though finding one is a real exercise in search-query-crafting.
另一种方法是获得第三方工具,尽管找到一个是搜索查询制作中的真正练习。
回答by Jeremiah
It was replaced with the commands: RMDIR or RD
它被替换为以下命令:RMDIR 或 RD
Delete all subdirectories with /S
用 /S 删除所有子目录
Use it quietly with the /Q
与 /Q 一起安静地使用它
Example:
例子:
RMDIR /S /Q Folder2Delete
RD /S /Q Folder2Delete
Documentation:
文档:
回答by raychi
Feeling nostalgic, I wrote my own deltree.exe. It works with both directories and files, and uses SHFileOperation() for speed.
怀旧的心情,写了自己的deltree.exe。它适用于目录和文件,并使用 SHFileOperation() 来提高速度。
https://github.com/ai7/toolbox/tree/master/deltree
https://github.com/ai7/toolbox/tree/master/deltree
deltree v1.01 [Mar 27 2015, 16:31:02] (gcc 4.9.1)
Usage: deltree [options] <path> ...
Options:
-y yes, suppresses prompting for confirmation
-s silent, do not display any progress dialog
-n do nothing, simulate the operation
-f force, no prompting/silent (for rm compatibility)
-r ignored (for rm compatibility)
Delete directories and all the subdirectories and files in it.
It takes wildcards and you can use it like unix rm:
它需要通配符,您可以像 unix rm 一样使用它:
deltree -rf *
回答by Rosberg Linhares
Nowadays, you can use Powershell to do the same task:
现在,您可以使用 Powershell 来完成相同的任务:
powershell -Command "Remove-Item 'PathToMyDirectory\*' -Recurse -Force"
回答by Jon Skeet
rmdir /s /q directory
回答by Ferruccio
$ help rd Removes (deletes) a directory. RMDIR [/S] [/Q] [drive:]path RD [/S] [/Q] [drive:]path /S Removes all directories and files in the specified directory in addition to the directory itself. Used to remove a directory tree. /Q Quiet mode, do not ask if ok to remove a directory tree with /S
回答by Sohail xIN3N
Actually RMDIR and RD commands in modern Windows operating system merge both the commands RD and Deltree of Win 98 in a single command. It's an internal command that's why you won't find any RD.exe and RMDIR.exe.
实际上现代Windows操作系统中的RMDIR和RD命令将Win 98的RD和Deltree命令合并在一个命令中。这是一个内部命令,这就是为什么您找不到任何 RD.exe 和 RMDIR.exe 的原因。
By typing this "RD /?" in cmd without double qoutes you'll get exactly what you want.
通过输入这个“RD /?” 在没有双 qoutes 的 cmd 中,你会得到你想要的。
回答by Theprogrammer7018
Use this:
用这个:
cd (your directory here)
del *.* /f /s /q
回答by v_b
Delete all files and subdirectories
删除所有文件和子目录
cd /d Directory && rd /s /q .\
回答by Gregg
to delete a directory and all it's contents recursively
递归删除目录及其所有内容
rd /s MY_DOOMED_DIR