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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7872113/
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 08:51:15  来源:igfitidea点击:

How to remove a folder and all its content from the current directory?

windowsbatch-file

提问by misctp asdas

This code that does not work:

此代码不起作用:

@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

回答by weberik

You were looking for this command:

您正在寻找此命令:

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

In your case just use /S,it will delete the whole directory tree by first asking the user if it should proceed, i.e.- displaying the following output to the screen:

在您的情况下,只需使用/S,它将首先询问用户是否应该继续,即在屏幕上显示以下输出,从而删除整个目录树:

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

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

where folderNameis the name of the folder (and its sub-folders) you wish to remove.

folderName您要删除的文件夹(及其子文件夹)的名称在哪里。

Tested on Windows 7, 64 bit.

在 Windows 7、64 位上测试。