Windows batch file to delete .svn files and folders

Marco Demaio picture Marco Demaio · Mar 28, 2010 · Viewed 21k times · Source

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.

Answer

ghostdog74 picture ghostdog74 · Mar 28, 2010

you can try

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