Windows批处理:从文本文件设定的变量 [英] Windows Batch: Set Variables from Text File

查看:242
本文介绍了Windows批处理:从文本文件设定的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯目前寻找设置在从linkes Windows批处理文件变量的txt文档的方法。

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://website1.com
http://website2.com
http://website3.com

我可以希望他们输出到批处理变量。例如:

I can hopefully output them to variables in the batch. 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"

任何帮助是AP preciated,先谢谢了!

Any help is appreciated, thanks in advance!

推荐答案

在FOR / F循环命令可以用来读取文本文件行:

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

您结束:

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

这篇关于Windows批处理:从文本文件设定的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆