如何从批处理脚本中单个变量的文本文件中读取所有内容? [英] How to read all content from text flie in single variable in Batch Script?

查看:145
本文介绍了如何从批处理脚本中单个变量的文本文件中读取所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在批处理脚本中的第一次经验,我正在尝试读取文本文件内容,并尝试在单个变量中设置其内容.我正在使用.bat文件运行脚本,但脚本无法正常工作.

我想在单个变量中设置文件的所有内容.
尝试了大多数示例,但失败了.

下面是我正在尝试的脚本

This is my first experience in batch script, i am trying to read text file content and trying to set its content in single variable i am using .bat file to run script but script not working.

i want to set all content of file in single variable.
tried most of example but failure.

below is my script which i am trying

cd "C:\documents and settings\%USERNAME%\desktop"
for /f "delims=" %%x in (Test.txt) do set Build=%%x
pause >nul
exit

这是我的文本文件


以下结果显示

And
below result is showing



我希望使用单个变量

推荐答案

cd "C:\documents and settings\%USERNAME%\desktop"
setlocal enableDelayedExpansion
for /f "useback delims=" %%x in ("Test.txt") do set "Build=!build! %%x"
echo %build%
pause >nul
exit

请注意,可以分配给变量的字符串的最大长度为8191个符号. 另外,某些特殊符号也可能破坏上面的脚本(%! ..)

Mind that the max length of a string you can assign to a variable is 8191 symbols. Also some special symbols could break the script above (%,! ..)

这篇关于如何从批处理脚本中单个变量的文本文件中读取所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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