Answer» Hi All,
I am trying to create a dos batch file that will ALLOW a user to input 4 DIGITS. From these 4 digits then search a data.txt file for a string beginning with those digits. If found then run a command associated to that line.
Example 1. 1234,goto c:\data\1234.bat Example 2. 2345,goto c:\data\2345.bat
the following file wil then run a command to perform a task based on the input.
then return to the main batch file when complete.
If anyone can help with this it would be much appreciated. Thankyou. Haski. I think that would be too HARD to do in batch, so I wrote you a vbscript. You just need to tell me the command you need executed, or if you know vbscript, you can edit it yourself. I put a note on the line where you should put your command in.
Code: [Select]Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("test.txt", ForReading)
Const ForReading = 1
lookFor = InputBox("Enter four digits. Any more will be truncated.") If lookFor = "" Then wscript.quit lookFor = Left(lookFor, 4)
Dim arrFileLines() i = 0 Do Until objFile.AtEndOfStream Redim Preserve arrFileLines(i) arrFileLines(i) = objFile.ReadLine i = i + 1 Loop objFile.Close
For i = 0 To UBound(arrFileLines) If InStr(arrFileLines(i), lookFor) <> 0 Then msgbox "Found on line: " & CStr(i+1) 'RUN YOUR COMMAND HERE 'use arrFileLines(i) for your command End If Next
Set objFile = Nothing Set objFSO = Nothing
I forgot to mention, you need to replace test.txt with the path to your file. EDIT: Added the truncate part I forgot.PM Reply sent. Post the responses here if that's ok.Could do this in a batch script as well.
|