Windows batch file to delete .svn files and folders

Posted by Marco Demaio on Stack Overflow See other posts from Stack Overflow or by Marco Demaio
Published on 2010-03-28T11:42:38Z Indexed on 2010/03/28 11:53 UTC
Read the original article Hit count: 575

Filed under:
|
|
|
|

Hi,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 extaclty ".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.

Thanks for any help!

© Stack Overflow or respective owner

Related posts about batch

Related posts about batch-file