如何批量加载.txt文件中的信息?

时间:2015-06-06 18:06:52

标签: batch-file save load

所以我最近一直在做一些小批量程序,但我无法设法使批处理文件加载信息。我就是这样做的。

:load_game
)
set /p something=
) > something.txt

在txt文件中:

something_is_awesome

就是它^^

如果我记得正确就是你如何保存文件...现在你如何以类似的方式加载它?

注意:我想一次做多个!

1 个答案:

答案 0 :(得分:4)

将一行写入文件使用echo my_information>something.txt(覆盖)

从文件中读取一行使用set /p something=<something.txt

写或读几行:

echo First line>something.txt
echo second line>>something.txt
echo and a third one>>something.txt

或者如果你想一次性写下所有这些:

@echo off
rem writing
(
  echo First line
  echo second line
  echo and a third one
)>something.txt

type something.txt
rem reading a
<something.txt (
  set /p one=
  set /p two=
  set /p three=
)
echo a. %one% %two% %three%

rem reading b
setlocal enabledelayedexpansion
set /a i=0
<something.txt (
  for /f "delims=" %%a in (something.txt) do (
    set /a i+=1
    set /p read[!i!]=
  )
)
echo b. %read[1]% %read[2]% %read[3]%

注意:与看似合乎逻辑的内容相反,set /p var=<<file.txt不起作用。

相关问题