I was wondering if it is possible to create a batch file that asks the user for input such as a "promocode" and searches for the "promocode" the user just input. If they are equal then I would want to open a file such as a word file, excel or sql. I want to be able to do this because for every different code a different file will need to be opened for coworkers. If I had a file that could be searched to see if the promocode is there then I will not need to keep on adding code for a new promocode they can just add the promocode to the text file.
If this code cannot be done please let me know.
@echo off
SET /P promocode="Type a promocode please:"
for %%d in (\path\ReadThisFileTest.txt) do (
if findstr "MCD758" == %promocode% goto :MCD758
:MCD758
start \path\test.docx
I have been trying a whole lot of things and here is one example. I don't know if you can even do this or if it is in the right order.
EDIT What is in the ReadThisFileTest.txt is the promocodes: MCD758 MCD555 MCD957. There are more than just those three but they are each on their own line in the text file. Also each has 3 letters followed by 3 numbers, as shown.
(Edited to reflect new information)
If the promocodes are identical to the prefix of the filenames you want to open, you can do:
@ECHO OFF
SET /P promocode="Type a promocode please: "
FOR /F "usebackq tokens=*" %%G IN ( "\path\ReadThisFileTest.txt" ) DO (
IF "%promocode%" == "%%G" (
START CMD /C "path\%%G.docx"
EXIT
)
)
ECHO No matching code found.