如何从当前目录中删除文件夹及其所有内容?

45

这段代码无法运行:

@echo off

if exist output @set /p checkdir= Output directory found. Do you wish to overwrite it?:

if  /I %checkdir% == Y  deltree /s /output 
pause

1
你发现了哪些问题?在许多当前版本的Windows中,DELTREE不再存在。根目录是当前目录吗? - PA.
1个回答

101
你在寻找这个命令:
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
在您的情况下,只需使用/S即可,它将首先询问用户是否应该继续,然后删除整个目录树,即在屏幕上显示以下输出:

"folderName, Are you sure (Y/N)?"

其中folderName是您希望删除的文件夹(及其子文件夹)的名称。

已在Windows 7 64位上进行测试。

RD 的功能良好。请确保添加绝对路径或 "cd" 到父目录,然后只传递子文件夹的名称。 - Marcell

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接