开发者

Windows batch file to delete .svn files and folders

开发者 https://www.devze.com 2022-12-25 09:17 出处:网络
In order to delete all \".svn\" files/folders/subfolders in \"myfolder\" I use this simple line in a batch file:

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 开发者_如何学Pythonwant 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.


you can try

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


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


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


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.

Windows batch file to delete .svn files and folders

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\" \""


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


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.


Here is my favorite, its simple and compact:

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

Fissh


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号