|
Answer» Hello,
is it possible to set multiple strings to one set command, or if not what is my other option?
I'm using the following code to LOOK for the string 100101 in a file, and output the results to a csv file with the name the file came from, the string, and the number of records found with that string. I'd also like to ADD the string 100131 to this.
Thx
@echo off setlocal enabledelayedexpansion set folder="C:\Mydir\" set string = 100101 set outputfile="C:\Mydir\myoutputtxt.csv" if exist %outputfile% del %outputfile% cd /d %folder% for /f "delims==" %%F in ('dir /b *.*') do ( set filename=%%~nxF set /a COUNT=0 for /f "delims==" %%L in ('type "!filename!"') do ( set line=%%L if "!line:~0,6!"=="%string%" set /a count+=1 ) echo !filename! ,!string!, !count!>> %outputfile% Code: [Select]@echo off setlocal enabledelayedexpansion set findfolder="C:\Mydir\" set outputfile="C:\Mydir\myoutputtxt.csv" set stringlist=100101 100131 100191 100161 if exist %outputfile% del %outputfile% cd /d %folder% for %%s in (%stringlist%) do ( set string=%%s for /f "delims==" %%F in ('dir /b /a-d *.*') do ( set filename=%%F set /a count=0 for /f "delims==" %%L in ('type "!filename!"') do ( set line=%%L if "!line:~0,6!"=="!string!" set /a count+=1 ) echo !filename! , !string! , !count!>>%outputfile% ) ) REM diagnostic type %outputfile% Personally I would put the outputfile in a different folder. You'll see why.
Why didn't you just CONTINUE the other thread, SINCE that is essentially the code I supplied you with there?
|