Windows批处理文件删除.svn文件和文件夹

发布于 2024-08-27 05:44:20 字数 610 浏览 9 评论 0原文

为了删除“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

酒浓于脸红 2024-09-03 05:44:20

你可以尝试

FOR /R myfolder %%X IN (.svn) DO (RD /S /Q "%%X" 2>nul)

you can try

FOR /R myfolder %%X IN (.svn) DO (RD /S /Q "%%X" 2>nul)
暗恋未遂 2024-09-03 05:44:20
for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *svn') do (rd /s /q "%%i")
for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *svn') do (rd /s /q "%%i")
挽手叙旧 2024-09-03 05:44:20

使用 find 类似的东西:

rm -rf `find . -name ".svn" -type d`

编辑:

我知道这是针对 Linux 的(我读的是 bash 而不是批处理)。我将其留在这里是为了帮助那些随机出现在这里的 Linux 用户:)

Something like that using find :

rm -rf `find . -name ".svn" -type d`

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 :)

时光磨忆 2024-09-03 05:44:20

实际上,这个答案来自 Jesper Rønn-Jensen
http://justaddwater.dk/2011/03/01/easy-delete-all-svn-subfolders-in-windows-explorer/

我认为分享起来要容易得多。我正在将几个项目从 .SVN 转换为 .GIT,所以这很棒。它向资源管理器添加了一个菜单项,以便您可以删除文件夹。创建 .reg 文件并将其导入。

输入图片此处描述

Windows Registry Editor Version 5.00
;
; Running this file will give you an extra context menu item in Windows Explorer
; "Delete SVN folders"
;
; For the selected folder, it will remove all subfolders named ".svn" and their content
; Tip from http://www.iamatechie.com/remove-all-svn-folders-in-windows-xp-vista/
;
; Enrichened with comments by Jesper Rønn-Jensen ( http://justaddwater.dk/ )
;
;
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
@="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
@="cmd.exe /c \"TITLE Removing SVN Folders in %1 && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""

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.

enter image description here

Windows Registry Editor Version 5.00
;
; Running this file will give you an extra context menu item in Windows Explorer
; "Delete SVN folders"
;
; For the selected folder, it will remove all subfolders named ".svn" and their content
; Tip from http://www.iamatechie.com/remove-all-svn-folders-in-windows-xp-vista/
;
; Enrichened with comments by Jesper Rønn-Jensen ( http://justaddwater.dk/ )
;
;
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
@="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
@="cmd.exe /c \"TITLE Removing SVN Folders in %1 && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""
盛夏已如深秋| 2024-09-03 05:44:20

奇怪的旁注:如果我使用

FOR /R . %%X IN (*.svn) DO (echo "%%X")

而不是


FOR /R myfolder %%X IN (.svn) DO (RD /S /Q "%%X")

不仅列出所有以 .svn 结尾的目录,它还列出所有内容。这是 For 命令中的一个 BUG,它给了我一个扩展,但我没有给它通配符。很奇怪。

Bizarre sidenote: if I use

FOR /R . %%X IN (*.svn) DO (echo "%%X")

instead of


FOR /R myfolder %%X IN (.svn) DO (RD /S /Q "%%X")

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

如若梦似彩虹 2024-09-03 05:44:20

如果要删除 Windows 中所有名为 .svn 的子文件夹
然后使用此内容创建批处理文件:

for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *.svn') do (
rd /s /q "%%i"
)

将其保存在文件 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:

for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *.svn') do (
rd /s /q "%%i"
)

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.

旧时模样 2024-09-03 05:44:20

这是我最喜欢的,它简单而紧凑:

find ./ -name ".svn" | xargs rm -Rf

费什

Here is my favorite, its simple and compact:

find ./ -name ".svn" | xargs rm -Rf

Fissh

赴月观长安 2024-09-03 05:44:20

删除windows上所有svn文件

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

.svn是文件夹名

To delete all svn files on windows

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

.svn is the folder name

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文