我与多个项目一起工作,我想递归删除所有名为“bin”或“obj”的文件夹,这样我就可以确保所有项目都会重新构建所有内容(有时这是迫使Visual Studio忘记所有以前的构建的唯一方法)。

是否有一种快速的方法来实现这一点(例如使用.bat文件),而不必编写。net程序?


当前回答

从使用Windows PowerShell删除obj, bin和ReSharper文件夹

与Robert H的答案非常相似,只是语法更短

powershell运行 Cd(更改目录)到项目文件夹的根目录 粘贴并运行下面的脚本 Dir .\ -include bin,obj,resharper* -递归| foreach($) {rd $_。fullname -Recurse -Force}

其他回答

这招对我很管用:

for /d /r . %%d in (bin,obj) do @if exist "%%d" rd /s/q "%%d"

根据superuser.com上的答案

与Steve的PowerShell脚本非常相似。我只是向它添加了TestResults和包,因为大多数项目都需要它。

Get-ChildItem .\ -include bin,obj,packages,TestResults -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }

实际上,你可以进一步使用PS的建议,在项目目录中创建一个vbs文件,就像这样:

Option Explicit
Dim oShell, appCmd
Set oShell  = CreateObject("WScript.Shell")
appCmd      = "powershell -noexit Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse -WhatIf }"
oShell.Run appCmd, 4, false

为了安全起见,我包含了-WhatIf参数,所以如果在第一次运行时对列表感到满意,可以删除它。

这是我用于递归删除所有BIN和OBJ文件夹的批处理文件。

创建一个空文件,命名为DeleteBinObjFolders.bat 复制粘贴下面的代码到DeleteBinObjFolders.bat 将DeleteBinObjFolders.bat文件移动到与解决方案(*.sln)文件相同的文件夹中。

@echo off
@echo Deleting all BIN and OBJ folders...
for /d /r . %%d in (bin,obj) do @if exist "%%d" rd /s/q "%%d"
@echo BIN and OBJ folders successfully deleted :) Close the window.
pause > nul

从使用Windows PowerShell删除obj, bin和ReSharper文件夹

与Robert H的答案非常相似,只是语法更短

powershell运行 Cd(更改目录)到项目文件夹的根目录 粘贴并运行下面的脚本 Dir .\ -include bin,obj,resharper* -递归| foreach($) {rd $_。fullname -Recurse -Force}