在 Windows CMD 上递归删除文件或文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12748786/
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
Delete files or folder recursively on Windows CMD
提问by modasser
How do I delete files or folders recursively on Windows from the command line?
如何从命令行在 Windows 上递归删除文件或文件夹?
I have found this solution where path we drive on the command line and run this command.
我找到了这个解决方案,我们在命令行上驱动路径并运行这个命令。
I have given an example with a .svn file extension folder:
我给出了一个带有 .svn 文件扩展名文件夹的示例:
for /r %R in (.svn) do if exist %R (rd /s /q "%R")
回答by DGuntoju
Please execute the following steps:
请执行以下步骤:
- Open the command prompt
- Change directory to the required path
Give the following command
del /S *.svn
- 打开命令提示符
- 将目录更改为所需路径
给出以下命令
del /S *.svn
回答by Lucas
The other answers didn't work for me, but this did:
其他答案对我不起作用,但这确实适用:
del /s /q *.svn
rmdir /s /q *.svn
/qdisables Yes/No prompting
/q禁用是/否提示
/smeans delete the file(s) from all subdirectories.
/s表示从所有子目录中删除文件。
回答by Sean Vaughn
You can use this in the bat
script:
您可以在bat
脚本中使用它:
rd /s /q "c:\folder a"
Now, just change c:\folder a
to your folder's location. Quotation is only needed when your folder name contains spaces.
现在,只需更改c:\folder a
到您的文件夹的位置。仅当您的文件夹名称包含空格时才需要引用。
回答by Anton
RMDIR path_to_folder /S
ex. RMDIR "C:\tmp" /S
前任。 RMDIR "C:\tmp" /S
Note that you'll be prompted if you're really going to delete the "C:\tmp" folder. Combining it with /Q switch will remove the folder silently (ex. RMDIR "C:\tmp" /S /Q
)
请注意,如果您真的要删除“C:\tmp”文件夹,系统会提示您。将它与 /Q 开关结合将无声地删除文件夹(例如RMDIR "C:\tmp" /S /Q
)
回答by khichar.anil
For file deletion, I wrote following simple batch file which deleted all .pdf's recursively:
对于文件删除,我编写了以下简单的批处理文件,该文件以递归方式删除了所有 .pdf:
del /s /q "\ad1pfrtg001\AppDev\ResultLogs\*.pdf"
del /s /q "\ad1pfrtg001\Project\AppData\*.pdf"
Even for the local directory we can use it as:
即使对于本地目录,我们也可以将其用作:
del /s /q "C:\Project\*.pdf"
The same can be applied for directory deletion where we just need to change delwith rmdir.
这同样适用于目录删除,我们只需要使用rmdir更改del。
回答by saleh ahmed
If you want to delete a specific extension recursively, use this:
如果要递归删除特定扩展名,请使用以下命令:
For /R "C:\Users\Desktop\saleh" %G IN (*.ppt) do del "%G"
回答by Michael Armes
You could also do:
你也可以这样做:
del /s /p *.{your extension here}
The /p
will prompt you for each found file, if you're nervous about deleting something you shouldn't.
该/p
会提示您为每个找到的文件,如果你担心删除的东西你不应该。
回答by Ferroao
After the blog post How Can I Use Windows PowerShell to Delete All the .TMP Files on a Drive?, you can use something like this to delete all .tmp for example from a folder and all subfolders in PowerShell:
在博客文章如何使用 Windows PowerShell 删除驱动器上的所有 .TMP 文件之后?,你可以使用这样的东西来删除所有 .tmp 例如从一个文件夹和 PowerShell 中的所有子文件夹:
get-childitem [your path/ or leave empty for current path] -include
*.tmp -recurse | foreach ($_) {remove-item $_.fullname}
回答by mjoao
Use the Windows rmdircommand
使用 Windows rmdir命令
That is, rmdir /S /QC:\Temp
即rmdir /S /QC:\Temp
I'm also using the ones below for some years now, flawlessly.
Check out other options with: forfiles /?
Delete SQM/Telemetry in windows folder recursively
forfiles /p %SYSTEMROOT%\system32\LogFiles /s /m *.* /d -1 /c "cmd /c del @file"
Delete windows TMP files recursively
forfiles /p %SYSTEMROOT%\Temp /s /m *.* /d -1 /c "cmd /c del @file"
Delete user TEMP files and folders recursively
forfiles /p %TMP% /s /m *.* /d -1 /c "cmd /c del @file"
我现在也在使用下面的那些,完美无瑕。
查看其他选项:forfiles /?
递归删除windows文件夹中的SQM/Telemetry
forfiles /p %SYSTEMROOT%\system32\LogFiles /s /m *.* /d -1 /c "cmd /c del @file"
递归删除windows TMP文件
forfiles /p %SYSTEMROOT%\Temp /s /m *.* /d -1 /c "cmd /c del @file"
递归删除用户 TEMP 文件和文件夹
forfiles /p %TMP% /s /m *.* /d -1 /c "cmd /c del @file"
回答by Max
For completely wiping a folder with native commands and getting a log on what's been done.
用于使用本机命令完全擦除文件夹并获取已完成操作的日志。
here's an unusual way to do it :
这是一种不寻常的方法:
let's assume we want to clear the d:\temp dir
假设我们要清除 d:\temp 目录
mkdir d:\empty
robocopy /mir d:\empty d:\temp
rmdir d:\empty