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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:48:50  来源:igfitidea点击:

What ever happened to deltree, and what's its replacement?

windowsbatch-filecmddos

提问by David Koelle

In earlier versions of MS-DOS - I want to say version 7, but I could be wrong - there was a deltreecommand, which recursively deleted all subdirectories and files from a given path.

在早期版本的 MS-DOS 中——我想说版本 7,但我可能错了——有一个deltree命令,它递归地删除给定路径中的所有子目录和文件。

deltreeno longer exists, but deldidn't seem to inherit the ability to delete a tree. del /sdeletes 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 rdcommand has the /sswitch to recursively remove sub-directories. You can combine it with the /qswitch 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 rdis notan exact replacement for deltreeas seemingly (almost) every page returned by Googling for windows deltreewould have you believe. The deltreecommand 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 delcommand 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 rdand delindividually 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. 单独使用rddel充其量是不方便的,因为它需要区分文件系统对象(文件/文件夹名称)是文件还是目录,这并不总是可行或实用。

You can copy the deltreecommand 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 deland rd; something like this:

另一种选择是创建一个批处理文件,同时调用delrd; 像这样:

::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 rdand del, passing in the arguments and redirecting the output to nulto avoid the error that one of them will invariably emit.

这会调用rdand 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