Windows Batch: Set Variables from Text File

前端 未结 2 459
灰色年华
灰色年华 2020-11-30 08:40

Im currently looking for a method to set variables in a windows batch file from linkes in txt document.

So for example, if the text file reads:

http:         


        
相关标签:
2条回答
  • 2020-11-30 08:43

    Here ya go! Have fun with this one.

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

    Lands you with the same results!

    0 讨论(0)
  • 2020-11-30 08:44

    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
    

    You end up with:

    var1=http://website1.com
    var2=http://website2.com
    var3=http://website3.com
    
    0 讨论(0)
提交回复
热议问题