Posted by & filed under Programming, Server Admin.

I had a task where there were thousands of files in a folder. Some of them contained a specific string and needed to be processed.

A quick n dirty method is to use grep (or windows grep in this case to identify the files and generate a list of filenames in plaintext. Then using a quick batch for…loop to process the files from the command line… nice and simple.

for /F "tokens=*" %A in (results.txt) do [command] %A

Substitute [process] for your command. %A contains the filepath from grep. In my case I wanted to just delete the file so I just replaced [command] with del. Done!

TechNet Reference:…

Leave a Reply

You must be logged in to post a comment.