Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am developing a script using MSDOS batch files for searching for strings in a directory
My requirement is as follows
I have a text file with a set of labels
I have to search if each label is used in any one of the files present in the directory
If its used in any one of the files, then i should be log it in the used variables.txt
If a variable is not used in any file, then i should log it in notused.txtexample
Input text file input.txt contains the following data
label1
label3
label5in the source directory there are 2 files a.txt and b.txt
the contents of a.txt islabel1: uses label1
the contents of b.txt is
label5: uses label5
when i run my batch file i should get 2 files as output
usedvariables.txt that contains
label1
label5
and notused.txt that contains
label3I am using MSDOS 5.0 and i am unable to get it using the find command
Code used enclosed.@echo on
del found.txt
del notfound.txt
for /f "delims=" %%i in (input.txt) do (
call :chkscript.bat %%i)
:chkscript.bat
SET name=%~1
FOR /f "delims=" %%q IN ('dir /b C:\temp\') DO (
FIND "%name%" /C /I %%q
IF %ERRORLEVEL% == 0 CALL :found %name%
PAUSE
)
:notfound
rem echo %name%>>notfound.txt
ECHO Name not found"
GOTO :EOF:found
echo %~1>>found.txt
GOTO :EOF

for /f %%a in (input.txt) do ( find /i "%%a" *.txt >nul 2>&1 && (echo found %%a) || (echo not found %%a) )tested on winxp cmd, not sure about msdos5.0

I am using MSDOS 5.0
Seriously? Then your script has a lot of issues.@echo on -- Valid :) del found.txt -- Valid :) del notfound.txt -- Valid :) for /f "delims=" %%i in (input.txt) do ( -- Invalid :( call :chkscript.bat %%i -- Invalid :( -- Valid :) ) -- Invalid :( -- Valid :) -- Valid :) :chkscript.bat -- Valid :) SET name=%~1 -- Technically valid :/ FOR /f "delims=" %%q IN ('dir /b C:\temp\') DO ( -- Invalid :( FIND "%name%" /C /I %%q -- Technically valid :/ IF %ERRORLEVEL% == 0 CALL :found %name% -- Invalid :( PAUSE -- Valid :) ) -- Invalid :( :notfound -- Valid :) rem echo %name%>>notfound.txt -- Valid :) ECHO Name not found" -- Valid :) GOTO :EOF -- Invalid :( -- Valid :) :found -- Valid :) echo %~1>>found.txt -- Technically valid :/ GOTO :EOF -- Invalid :(
That's 13 valids to 24 total lines. Almost half (or more than half, if you remove the blank lines) of that script won't work in true MS-DOS.

This is just nitpicking but wouldn't "goto :eof" class as "Technically valid :/" provided that the script has a label called :eof? (I can see that it doesn't)

Judago: This is just nitpicking but wouldn't "goto :eof" class as "Technically valid :/" provided that the script has a label called :eof?
Had he an :EOF, then it'd be valid, yes. As written, however, the GOTO will throw an error. And yes, which is my classification for the invalid lines. (Technically valid are lines I don't think will throw an error, but won't do/give him what he wants.)

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |