你如何从加载在批处理.txt文件的信息? [英] How do you load information from a .txt file in batch?

查看:151
本文介绍了你如何从加载在批处理.txt文件的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我最近一直在做一些小批量的程序,但我不能管理,使该批处理文件负载信息。这就是我会做。

So I have been doing some small batch programs lately but I can't manage to make the batch file load information. This is how i would do it.

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

在txt文件:

something_is_awesome

something_is_awesome

这是^^

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

If i remember it right that is how you SAVE a file... now how do you LOAD it in a similar way?

请注意:我愿做多一次

推荐答案

写一行到文件中使用回声my_information> something.txt (覆盖)

to WRITE a line to a file use echo my_information>something.txt (overwriting)

以从文件中读取使用行设置/ p东西= LT; something.txt

to READ a line from a file use set /p something=<something.txt

写或读几行:

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

如果你想写他们都一气呵成:

or if you want to write all of them in one go:

@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]%

请注意:相反的是似乎是合乎逻辑,设置/对VAR =&LT;&LT; file.txt的不正常工作

NOTE: contrary to what seems logical, set /p var=<<file.txt does NOT work.

这篇关于你如何从加载在批处理.txt文件的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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