Command Line string search

G

Guest

Hello to all,

I need help with the following please.

[OS = XP Pro]

I want to print to file, a list of files in a specific directory that
contain a certain string. This listing must also include the date of said
file.

I'm able to create the list of files with FINDSTR /M
[[drive:][path]filename]. This returns all the fiile names which meet the
criteria but FINDSTR does not return the date of the file, which I also need.

I thought I may be able to use the FOR and or DIR commands in conjunction
with FINDSTR and pipe this to a text file. I've been reading the help file on
FOR but it is not clear to me how to use the results from FINDSTR as an input
variable.

Any help in setting me on the correct path to solving this is greatly
appreciated.

Regards,

Hal
Michigan, USA
 
P

Pegasus \(MVP\)

Hal said:
Hello to all,

I need help with the following please.

[OS = XP Pro]

I want to print to file, a list of files in a specific directory that
contain a certain string. This listing must also include the date of said
file.

I'm able to create the list of files with FINDSTR /M
[[drive:][path]filename]. This returns all the fiile names which meet the
criteria but FINDSTR does not return the date of the file, which I also need.

I thought I may be able to use the FOR and or DIR commands in conjunction
with FINDSTR and pipe this to a text file. I've been reading the help file on
FOR but it is not clear to me how to use the results from FINDSTR as an input
variable.

Any help in setting me on the correct path to solving this is greatly
appreciated.

Regards,

Hal
Michigan, USA

How about this:

dir /ad "c:\SomeFolder\Some Subfolder" | find /i "Some String" >
c:\FileList.txt

You don't really need the FOR command in this case but here is
how you could use it in a batch file:

Line1 @echo off
Line2 SetLocal EnableDelayedExpansion
Line3
Line4 set count=0
Line5 for /F "tokens=*" %%* in ('dir /ad "c:\SomeFolder\SomeSubfolder" ^|
find /i "SomeString"') do (
Line6 set Line=%%*
Line7 set count=!count! + 1
Line8 echo Line !count!=!Line!
Line9 )
Line10 EndLocal
 

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

Top