Windows package: setting variables from a text file

I'm currently looking for a method to set variables in a Windows batch file from links in a txt document.

So, for example, if a text file reads:

http://website1.com http://website2.com http://website3.com 

I hope to output them to variables in the package. Example:

 set var1="Line one of text file, ex: http://website1.com" set var2="Line two of text file, ex :http://website2.com" set var3="Line three of text file, ex: http://website3.com" 

Any help is appreciated, thanks in advance!

+4
source share
2 answers

The FOR / F loop command can be used to read lines from a text file:

 @echo off setlocal ENABLEDELAYEDEXPANSION set vidx=0 for /F "tokens=*" %%A in (sites.txt) do ( SET /A vidx=!vidx! + 1 set var!vidx!=%%A ) set var 

The result is:

 var1=http://website1.com var2=http://website2.com var3=http://website3.com 
+14
source

Here you go! Enjoy it.

 ( set /p var1= set /p var2= set /p var3= )<Filename.txt 

Land with the same results!

+18
source

All Articles