deltree 发生了什么,它的替代品是什么? [英] What ever happened to deltree, and what's its replacement?

查看:21
本文介绍了deltree 发生了什么,它的替代品是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

deltree 不再存在,但 del 似乎没有继承删除树的能力.del/s 删除文件,但不删除文件夹.

deltree no longer exists, but del didn't seem to inherit the ability to delete a tree. del /s deletes files, but not folders.

如何轻松地(即在一个命令中)从批处理文件中删除一棵树?

How to you easily (i.e., in one command) delete a tree from a batch file?

推荐答案

正如其他人提到的,rd 命令具有 /s 开关以递归删除子目录.您可以将它与 /q 开关结合起来,在不提示的情况下强行删除子目录(及其内容)

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 c:foobar

每个人都缺少的是,rd不是deltree 的完全替代品,看起来(几乎) 谷歌搜索 windows deltree 返回的每个页面都会让您相信.deltree 命令适用于目录和文件,使其成为一个方便、通用的删除命令.即以下两项均有效:

What everybody is missing is that rd is not an 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:

deltree /y c:foobar
deltree /y c:az.txt

然而rd(并不奇怪)仅适用于目录.因此,只有这些命令中的第一个是有效的,而第二个给出并出错并保留未删除的文件:

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 /s /q c:foobar
rd /s /q c:az.txt

此外,del 命令仅适用于文件,而不适用于目录,因此只有第二个命令有效,而第一个命令出错:

Further, the del command only works for files, not directories, so only the second command is valid while the first gives an error:

del /f /q c:foobar
del /f /q c:az.txt

没有像 deltree 那样可以删除文件和目录的内置方法.单独使用 rddel 充其量是不方便的,因为它需要区分文件系统对象 (file-/folder-name) 是文件还是目录,而这并不总是可能或实用.

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 命令,但它只能在 32 位版本的 Windows 上运行,因为它是一个 16 位 DOS 命令(即使在 Windows 9x 中也是如此).

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).

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

Another option is to create a batch-file that calls both del and rd; something like this:

::deltree.bat

@echo off
rd  %* 2> nul
del %* 2> nul

你会这样称呼它:

deltree.bat /s /q /f c:foobar
deltree.bat /s /q /f c:az.txt

这会同时调用 rddel,传入参数并将输出重定向到 nul 以避免其中之一的错误总是发出.

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.

您可能希望自定义行为以适应或简化参数或允许错误消息,但即便如此,它也不理想,也不能直接替代 deltree.

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.

另一种方法是使用第三方工具,尽管找到一个是搜索-查询-制作的真正练习.

An alternative is to get a third-party tool, though finding one is a real exercise in search-query-crafting.

这篇关于deltree 发生了什么,它的替代品是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆