I'm trying to add Date Modified and File Name information into the output file my batch script creates.
I have a file (info.txt) that contains multiple strings on separate lines. For each string in info.txt, my batch file loops through each text file in a directory finding said string and outputting that line to a separate file called results.txt. See code below.
for /F %%i in (info.txt) do (
echo Searching files containing string: %%i
findstr /C:%%i /I \\directory*.txt >> results.txt )
For each line in results.txt I would like to add the File Name and Date Modified of each file that the string was found in. Right now results.txt looks something like this:
//directory/file1.txt:Line of data where "string" was found
But I would like it to look more like this:
Date modified of file1.txt | file1.txt | Line of data where string was found
Thanks in advance for the help!
The output of findstr
is processed in the inner for
loop - an each string from the output is split on two parts (filename %%B
, remainder %%C
). %%~tB
is a file date and time, %%~nxB
is a file name and extension.
for /f %%A in (info.txt) do (
echo Searching files containing string: %%A
for /f "delims=: tokens=1*" %%B in ('findstr /C:%%A /I directory*.txt') do (
echo %%~tB ^| %%~nxB ^| %%C >> results.txt
)
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.