For loop Delete question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

For loop Delete question

#1 Post by SIMMS7400 » 17 Jun 2017 08:52

What is the best way to delete ALL files in a specific that DO NOT have a certain string as a PREFIX:

String : CC_NEQ

Thanks!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: For loop Delete question

#2 Post by aGerman » 17 Jun 2017 09:03

Untested:

Code: Select all

@echo off &setlocal

set "folder=C:\test"
set "prefix=CC_NEQ"

pushd "%folder%"
for /f "delims=" %%i in ('dir /a-d /b ^|findstr /vbc:"%prefix%"') do ECHO del /f "%%i"
popd

PAUSE

Remove ECHO and PAUSE if it displays the right files to delete.

Steffen

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: For loop Delete question

#3 Post by SIMMS7400 » 17 Jun 2017 11:07

Works great, thank you sir!!!

Post Reply