Delete all folders containing a string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Conk1
Posts: 12
Joined: 04 Dec 2009 09:43

Delete all folders containing a string

#1 Post by Conk1 » 21 Jul 2011 06:40

Hello I want to make a batch that deletes these folders and all their contents:
C:\found.000\, C:\found.001\, C:\found.002\, etc
or more accurately %systemdrive%\found.000

So far I have this:
for /d %%X in (found.0*) do rd /a /f /s /q "%%X"

However, this only does it if the current directory is C:\
I've tried playing around with adding the directory but it only seems to work when when the current directory is set to certain folders.

Can anyone make a better solution? Ideally I want:
Delete all folders in %systemdrive% containing found.0*

Thanks in advance

shiva
Posts: 18
Joined: 11 Jul 2011 03:53

Re: Delete all folders containing a string

#2 Post by shiva » 21 Jul 2011 07:47

hi,
i used the line given by you,
the complete code was

@echo off

for /D /R %%i in (*.*) do (

cd %%i
for /d %%X in (found.0*) do rd /s /q "%%X"
cd ..
)
cd..
@echo on


save this in c:/abc/
it will delete all the directories in this directory,
run this file where ever u want do delete
thank you

Conk1
Posts: 12
Joined: 04 Dec 2009 09:43

Re: Delete all folders containing a string

#3 Post by Conk1 » 21 Jul 2011 08:53

Thank you :)

shiva
Posts: 18
Joined: 11 Jul 2011 03:53

Re: Delete all folders containing a string

#4 Post by shiva » 02 Aug 2011 06:02

you are welcome

Post Reply