Page 1 of 1

Delete all folders containing a string

Posted: 21 Jul 2011 06:40
by Conk1
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

Re: Delete all folders containing a string

Posted: 21 Jul 2011 07:47
by shiva
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

Re: Delete all folders containing a string

Posted: 21 Jul 2011 08:53
by Conk1
Thank you :)

Re: Delete all folders containing a string

Posted: 02 Aug 2011 06:02
by shiva
you are welcome