Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
If statement based on search result
Name: cyoulater Date: December 11, 2007 at 09:41:15 Pacific OS: DOS CPU/Ram: 512 Product: Dell
Comment:
I want to create a scenario by which I can query a text file for a certain string and if the string exist then print that the search was successful. I'am writing my first DOS batch program and need some major help. thanks
Name: worldlibrary Date: December 11, 2007 at 10:25:21 Pacific
Reply:
I didn't write this....But perhaps it will get you started.
@echo off if %1.==GOTO. %1 %2 SET FMTEM=%TEMP% SET FMOUT=%FMTEM%\FINDM.TXT if not %2.==. goto DO echo I use FIND.exe /I /N to find a word in a wild-card group of files. echo Syntax: %0 word filegroup [output_file] echo Default output file = %FMOUT% goto END :DO SET FMYES= if not %3.==. set FMOUT=%3 if exist %FMOUT% del %FMOUT% for %%f in (%2) do call %0 GOTO DO1 %1 %%f if %FMYES%.==Y. type %FMOUT% if %FMYES%.==Y. echo %0: Word "%1" occurs in (%2) as listed in %FMOUT%. if not %FMYES%.==Y. echo %0: Word "%1" was not found in %2. if exist %FMTEM%\FIND.RPT del %FMTEM%\FIND.RPT for %%w in (OUT TEM YES) do set FM%%w= goto END :DO1 find /N /I "%3" %4 >%FMTEM%\FIND.RPT if errorlevel 1 goto end set FMYES=Y type %FMTEM%\FIND.RPT >>%FMOUT% :END
0
Response Number 2
Name: worldlibrary Date: December 12, 2007 at 08:18:02 Pacific
Reply:
This might be a bit simpler. Change BAT to txt and AWK to the string.
You can add all the @echo off ,labels and cls to suite your needs.
for %%f in (*.bat) do find /I "awk" %%f >>find.rpt
Summary: Hello. I'm trying to write a batch file to purge files based on how old they are. The solution I've had recommended to me involves the following command: DIR \ | find /I "/" > del.log The code then u...
Summary: Hello, I have batch file that starts a small exe file to connect to a device through COM 1 to send some data. Here's where I need some help. The program does not return error codes, but I need to us...
Summary: This ~may~ be of help to you. From the latest LangaList newsletter; ============================================= 5) Finding a "Lost Gem" Hi Fred: Love your Plus! edition immensely! Has been regularly...