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

查看:80
本文介绍了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的精确替代品(

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:\baz.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:\baz.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:\baz.txt

没有像deltree那样的内置方法来删除文件和目录.单独使用rddel最多是不便的,因为它需要区分文件系统对象(文件名/文件夹名)是不是总是不可能或不实际的文件或目录.

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命令,但是由于它是16位DOS命令(即使在Windows 9x中也是如此),因此仅在32位版本的Windows上有效.

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:\baz.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.

另一种方法是获得第三方工具,尽管找到它是在search-query-crafting中真正的练习.

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

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

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