for, findstr, and dir

G

Guest

I've been trying to do generate a list of file names with dates that contain
a specific string. Can anyone help with this please. Below is what I came up
with but I don't know this will truely give me all files that contain the
string "EC1_FRP_UT" and the data it was created. The other bad thing here is
that each time the file name is passed to dir, to gives the directory heading
info as well.

K:\Official> FOR %f in (*.*) DO findstr /M "EC1_FRP_UT" *.* | dir %f >>
myfile.txt

Thanks in advance

Hal
 
G

Guest

Jon, your solution would only return files which contained the string in the
file name, not within the file. I need file name and date of files which have
the string in the data of the file.

But thanks anyhow.

Hal
 
J

Jon

Apologies. Misunderstood the question.

You could perhaps include some parsing of the output to get rid of the
directory heading info

eg (in a .bat batch file)


@echo off
FOR /f %%f in ('findstr /m "EC1_FRP_UT" *.*') DO dir %%f >> temporary.txt
2>errors.txt

findstr "2001" temporary.txt 2> errors.txt > myfile.txt
findstr "2002" temporary.txt 2> errors.txt >> myfile.txt
findstr "2003" temporary.txt 2> errors.txt >> myfile.txt
findstr "2004" temporary.txt 2> errors.txt >> myfile.txt
findstr "2005" temporary.txt 2> errors.txt >> myfile.txt

del errors.txt
del temporary.txt



Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top