So I am trying to create batch script that does a findstr of two variables. I am reading from a specific file where I need the variables from.
The variables I need are
NetPath=
NetPathmed=
And my goal is to use the two variables to do a network map drive. In the first findstr I need everything after the NetPath= and in the second I need just a specific amount of data from the string. A normal NetPathMed looks like this
NetPathmed=\\**IPaddress**:C:\folder\file.
I just need the IP address
For example the batch I created looks like this
cd: C:\folder\
set var1="findstr 'NetPath=' file.ini"
for /f "tokens=1,2 delims== " %%a in ("%var1%") do set net=%%a&set path=%%b
Set var2= "findstr 'NetPathMed' opsetup.ini"
for /f "tokens=1,2,3 delims==/ " %%c in ("%var2%") do set net=%%c&set path=%%d &set net=%%e
net use var1(driveletter) \var2(IPaddress)\network folder /persistent:yes
Well - fixed a bit. Very difficult to tell where the elements you are extracting from your files actually are and which you wish to assemble into your command.
Made worse by your using 'NetPathMed
in your code butNetPathmedin the data line you have given. If you don't use the/iswitch,findstr` is case-sensitive.Other errors:
cd:should not have a:.The command within the parentheses of the
for /fshould be enclosed in SINGLE quotes.FINDSTRlikes"double quotes"I couldn't tell whether you wanted the data to be placed in
var1andvar2or what - an example of the relevant contents of the two files and the required command to be generated would have been helpful.I chose to assign all of the text after the
=in the selected line from the first file intovar1(because that's what you said)The first part in
%%ais token1 =NetPath(not used) and the second token (*=the rest of the line) appears in the next metavariable (%%b)Similarly, parsing the EXACT DATA that you posted, you are only using the second and third tokens
Note that you specified
/not\. Different animal. Chalk and cheese.So - all you'd need to do is assemble the various elements
%var1%%%cand%%dtogether with the fixed text you require, replace theechowithnet useafter testing and you should be off...