Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line tool to delete folder with a specified name recursively in Windows?

I want to delete every "_svn" in every folder and subfolder...

For example

c:\
  proyect1
   _svn
   images
     _svn
     banner
       _svn
     buttons
       _svn

Then I run something like

rm-recurse c:\proyect1 _svn

And I should get:

c:\
  proyect1
   images
     banner
     buttons

The ideal thing would be a tiny stand-alone EXE or something like that.

-- Thanks Grant, as soon as I posted the question I saw SVN documentation about the SVN export command, but I also want to delete the _vti_* folders stuff Visual Studio creates, so I'll also explore the for solution.

like image 455
opensas Avatar asked Feb 06 '09 17:02

opensas


People also ask

How do I delete a recursive folder in Windows?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

How do I delete a folder and subfolders in CMD?

rmdir “C:\Users\username\Desktop\Info” If you want to delete all the files and subfolders in the folder you want to delete, add the /s parameter. This will ensure that the folder is removed including the subfolders and files in it.

How do I delete a folder using command prompt?

To delete folders (also called directories) on your PC, use Windows' built-in rmdir command. This command helps you delete folders as well as their subfolders and the files inside them. Warning: Know that the rmdir command removes folders without moving them to the Recycle Bin.


3 Answers

Similar to BlackTigerX's "for", I was going to suggest

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

like image 193
JMD Avatar answered Oct 16 '22 08:10

JMD


Time to learn some PowerShell ;o)

Get-ChildItem -path c:\projet -Include '_svn' -Recurse -force | Remove-Item -force -Recurse

The first part finds each _svn folder recursively. Force is used to find hidden folders. Second part is used to delete these folders and their contents. Remove commandlet comes with a handy "whatif" parameter which allows to preview what will be done.

PowerShell is available for Windows XP and Windows Vista. It is present on Windows 7 and on Windows Server 2008 R2 by default.

It's a MS product, it's free, and it rocks!

like image 38
Cédric Rup Avatar answered Oct 16 '22 08:10

Cédric Rup


For inclusion/invocation from within a BATCH file use (say for removing Debug and Release folder):

for /d /r . %%d in (Debug Release) do @if exist "%%d" echo "%%d" && rd /s/q "%%d"

double % are required within a batch file to work as escape chars. Else it reports error of syntax.

Thanks.

like image 25
Rajesh Gautam PhD Avatar answered Oct 16 '22 09:10

Rajesh Gautam PhD