Batch script for a very common task

BatchFile to remove files using a selected keywordSoftware slaves. You don’t need to code them in a programming language. Even a simple batch file, with few simple commands can be an excellent slave.

Here’s a common problem?
There’s a folder with lot of files. You need to search through these files and separate the files containing a particular word.

Here’s a batch script to find a word in a series of text files in a folder and move the matching file to a separate folder.

@echo off
REM finds specified text in files in the current directory
REM and moves it to new folder if the specified text is found.
REM Nov 5th 2013
set /p id="Enter ID: " %=%
echo Files containing: %id%
findstr /i /b /m "\<%id%\>" *.*
mkdir %id%
for /f %%e in ('findstr /i /b /m \<%id%\> *.*') do move /-Y %%~fse %id%
for /f &quot;usebackq&quot; %%d in (`&quot;dir /ad/b | sort /R&quot;`) do if %%d == %id% rd "%%d"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s