0

In my BAT file, i want to read these data from .txt file and need to set each data into one variable

    SQLUserName=MFiles
    WrapperSQLServerName=usa.com
    WrapperDatabase=Wrapper
    WrapperAssemblyLocation=D:\Assembly
    MFilesNetworkAddress=USA-S1
    MFilesVaultName=MF2
    MFilesUsername=User
    MFilesPassword=
    MFilesVaultGUID={26F30-E120-408C-8035-04D85D6}
    MFilesWebServerURL=www.WebServer.com
    SQLMailProfileName=NoReply
    [email protected]

I tried with this code

FOR /F "tokens=2 delims==" %%a IN ('find "WrapperSupportEmail" ^<config.txt') DO SET SupportEmail=%%a

But it throws error

find is not recognized as an internal or external command operable program or batch file

Please help me

Thejus T V

1
  • Try running find in an interactive command prompt. Commented Jul 27, 2015 at 10:40

3 Answers 3

3

If the schema of your input file is fixed (keyword=value) and you want to assign all values to an environment variabel named keyword it is very, very easy. try this:

for /f "tokens=1,2 delims==" %i in (config.txt) do set %i=%j

remember to change %i and %j to %%i and %%j if you want to put this call into a cmd-file.

Sign up to request clarification or add additional context in comments.

5 Comments

as the file is fine formatted: for /f "delims=" %i in (config.txt) do set %i
Text file always in the same for formatted as show above.So how we can set each key value into one variable?
As indicated in @Stephan's comment above yours. It is equivalent to execute: set SQLUserName=MFiles, then set WrapperSQLServerName=usa.com, etc...
@Aacini I want to read the data from .txt file and set to a variable from Batch file
@thejustv: Please, modify your original question and insert an additional description that clearly state what you want as result!
0

when two members with high reputation tell you it works, then it shouldn't be the worst of all ideas to at least try it.

rem @echo off
for /f "delims=" %%i in (config.txt) do set _%%i
pause
set _

I REMd the @echo off, so you can watch, how every single line get's processed.

(Your original error find is not recognized ... is probably because you messed up your %path%-variable, but you don't need find for this task.)

Comments

0

My code is correct one only. Only issue is windows cant locate find.exe. I included the .exe on same location and after that everything works fine.

Its working fine in Win 7 and Win 10 without adding Find.exe

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.