如何在 Windows 中使用 bat 文件删除文件夹和所有内容?

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

How to delete a folder and all contents using a bat file in windows?

windowsbatch-filecommanddelete-file

提问by learner

I want to delete a folder with all files and subfolders using a bat file.

我想使用 bat 文件删除包含所有文件和子文件夹的文件夹。

I have tried the following, but it is not working:

我尝试了以下方法,但它不起作用:

@DEL D:\PHP_Projects\testproject\Release\testfolder*.*

Can anybody help?

有人可以帮忙吗?

回答by Jon

@RD /S /Q "D:\PHP_Projects\testproject\Release\testfolder"

Explanation:

说明

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

移除(删除)一个目录。

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 user3319853

  1. del /s /q c:\where ever the file is\*
  2. rmdir /s /q c:\where ever the file is\
  3. mkdir c:\where ever the file is\
  1. del /s /q c:\where ever the file is\*
  2. rmdir /s /q c:\where ever the file is\
  3. mkdir c:\where ever the file is\

回答by Alexander Bondarchuk

del /s /q c:\where ever the file is*

del /s /qc:\文件所在的位置*

This deletes all files in the folder and subfolders, but leaves empty subfolders

这将删除文件夹和子文件夹中的所有文件,但留下空子文件夹