我想删除所有 bin 和 obj 文件夹以强制所有项目重建所有内容 [英] I want to delete all bin and obj folders to force all projects to rebuild everything

查看:31
本文介绍了我想删除所有 bin 和 obj 文件夹以强制所有项目重建所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处理多个项目,我想递归删除所有名为bin"或obj"的文件夹,我确信所有项目都会重建所有内容(有时这是强制 Visual Studio 忘记的唯一方法)所有关于以前的版本).

I work with multiple projects, and I want to recursively delete all folders with the name 'bin' or 'obj' that way I am sure that all projects will rebuild everything (sometimes it's the only way to force Visual Studio to forget all about previous builds).

是否有一种无需编写 .NET 程序即可快速完成此操作的方法(例如使用 .bat 文件)?

Is there a quick way to accomplish this (with a .bat file for example) without having to write a .NET program?

推荐答案

这取决于您喜欢使用的 shell.

This depends on the shell you prefer to use.

如果您在 Windows 上使用 cmd shell,那么以下应该可以工作:

If you are using the cmd shell on Windows then the following should work:

FOR /F "tokens=*" %%G IN ('DIR /B /AD /S bin') DO RMDIR /S /Q "%%G"
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"

如果您使用 bash 或 zsh 类型的 shell(例如 Windows 上的 git bash 或 babun 或大多数 Linux/OS X shell),那么这是一种更好、更简洁的方式来做您想做的事:

If you are using a bash or zsh type shell (such as git bash or babun on Windows or most Linux / OS X shells) then this is a much nicer, more succinct way to do what you want:

find . -iname "bin" | xargs rm -rf
find . -iname "obj" | xargs rm -rf

这可以用 OR 减少到一行:

and this can be reduced to one line with an OR:

find . -iname "bin" -o -iname "obj" | xargs rm -rf

请注意,如果您的文件名目录包含空格或引号,则 find 将按原样发送这些条目,而 xargs 可能会拆分为多个条目.如果你的 shell 支持它们,-print0-0 将解决这个缺点,所以上面的例子变成:

Note that if your directories of filenames contain spaces or quotes, find will send those entries as-is, which xargs may split into multiple entries. If your shell supports them, -print0 and -0 will work around this short-coming, so the above examples become:

find . -iname "bin" -print0 | xargs -0 rm -rf
find . -iname "obj" -print0 | xargs -0 rm -rf

和:

find . -iname "bin" -o -iname "obj" -print0 | xargs -0 rm -rf

如果你使用的是 Powershell,那么你可以使用这个:

If you are using Powershell then you can use this:

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

Robert H 在下面的回答 中所见 - 只要确保您将 Powershell 的答案归功于他而不是我,如果你选择对任何事情投赞成票 :)

as seen in Robert H's answer below - just make sure you give him credit for the powershell answer rather than me if you choose to up-vote anything :)

首先在安全的地方运行您选择的任何命令来测试它当然是明智的!

It would of course be wise to run whatever command you choose somewhere safe first to test it!

这篇关于我想删除所有 bin 和 obj 文件夹以强制所有项目重建所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆