Windows批处理文件删除.svn文件和文件夹
为了删除“myfolder”中的所有“.svn”文件/文件夹/子文件夹,我在批处理文件中使用这个简单的行:
FOR /R myfolder %%X IN (.svn) DO (RD /S /Q "%%X")
这有效,但如果没有“.svn”文件/文件夹,批处理文件会显示一条警告说: “系统找不到指定的文件。” 这个警告非常吵闹,所以我想知道如何让它明白,如果它没有找到任何“.svn”文件/文件夹,他必须跳过 RD 命令。
通常使用通配符就足够了,但在这种情况下我不知道如何使用它们,因为我不想删除扩展名为 .svn 的文件/文件夹,但我想删除完全名为“.svn”的文件/文件夹。 svn”,所以如果我这样做:
FOR /R myfolder %%X IN (*.svn) DO (RD /S /Q "%%X")
它不会再删除完全命名为“.svn”的文件/文件夹。 我也尝试过这个:
FOR /R myfolder %%X IN (.sv*) DO (RD /S /Q "%%X")
但它也不起作用,他什么也没删除。
In order to delete all ".svn" files/folders/subfolders in "myfolder" I use this simple line in a batch file:
FOR /R myfolder %%X IN (.svn) DO (RD /S /Q "%%X")
This works, but if there are no ".svn" files/folders the batch file shows a warning saying: "The system cannot find the file specified."
This warning is very noisy so I was wondering how to make it understand that if it doesn't find any ".svn" files/folders he must skip the RD command.
Usually using wild cards would suffice, but in this case I don't know how to use them, because I don't want to delete files/folders with .svn extension, but I want to delete the files/folders named exactly ".svn", so if I do this:
FOR /R myfolder %%X IN (*.svn) DO (RD /S /Q "%%X")
it would NOT delete files/folders named exactly ".svn" anymore.
I tried also this:
FOR /R myfolder %%X IN (.sv*) DO (RD /S /Q "%%X")
but it doesn't work either, he deletes nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
你可以尝试
you can try
使用 find 类似的东西:
编辑:
我知道这是针对 Linux 的(我读的是 bash 而不是批处理)。我将其留在这里是为了帮助那些随机出现在这里的 Linux 用户:)
Something like that using find :
Edit:
I know this is for linux (I read bash instead of batch). I'm leaving it here to help Linux users that would randomly end-up here :)
实际上,这个答案来自 Jesper Rønn-Jensen
http://justaddwater.dk/2011/03/01/easy-delete-all-svn-subfolders-in-windows-explorer/
我认为分享起来要容易得多。我正在将几个项目从 .SVN 转换为 .GIT,所以这很棒。它向资源管理器添加了一个菜单项,以便您可以删除文件夹。创建 .reg 文件并将其导入。
Actually, this answer is from Jesper Rønn-Jensen at
http://justaddwater.dk/2011/03/01/easy-delete-all-svn-subfolders-in-windows-explorer/
I thought it was so much easier I'd share. I'm converting several projects from .SVN to .GIT, so this was great. It adds a menu item to Explorer so you can remove the folders. Create a .reg file, and import it.
奇怪的旁注:如果我使用
而不是
不仅列出所有以 .svn 结尾的目录,它还列出所有内容。这是 For 命令中的一个 BUG,它给了我一个扩展,但我没有给它通配符。很奇怪。
肯
Bizarre sidenote: if I use
instead of
not only does it list all directories ending in .svn, it lists ALL THEIR CONTENTS as well. This is a BUG in the For command, it gave me an expansion where I gave it no wild card. Very strange.
Ken
如果要删除 Windows 中所有名为 .svn 的子文件夹
然后使用此内容创建批处理文件:
将其保存在文件 del_All_Dot_SVN_Folders.cmd 中。运行它。你完成了。
感谢 http://www.axelscript。 com/2008/03/11/delete-all-svn-files-in-windows/
请记住上面的代码有 .svn 而链接中的代码只有 *svn 所以它更好
让 .svn 不会意外地产生不良效果。
If you want to delete all sub folders named .svn in Windows
then create batch file with this content:
save it in a file del_All_Dot_SVN_Folders.cmd . Run it. Your done.
Thanks to http://www.axelscript.com/2008/03/11/delete-all-svn-files-in-windows/
Remember the above code has .svn whereas the code in the link has only *svn so its better
to have the .svn to not accidentally have undesired effect.
这是我最喜欢的,它简单而紧凑:
find ./ -name ".svn" | xargs rm -Rf
费什
Here is my favorite, its simple and compact:
find ./ -name ".svn" | xargs rm -Rf
Fissh
删除windows上所有svn文件
.svn是文件夹名
To delete all svn files on windows
.svn is the folder name