如何在批处理文件中获取文件变量 [英] How to get a file Variables in Batch-File

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

问题描述

让我们想象一个批处理游戏将您的进度保存在file.bat文件中,当我们编辑该文件时,我们得到了:

Let's imagine a Batch game saves your progress in a file.bat file, when we edit that file we got :

set Health=100
set Sword=Gold

我在批处理文件中使用了此命令,但没有用:

i used this command in a Batch file but it's didn't work :

for /f "eol=- delims=" %%a in (file.bat) do set "%%a"
echo Your health is %Health%
echo Your sword is made of %Sword%

将其留空.

但是,如果我制作了上述文件,但删除了 set (仅Health = 100和Sword = Gold(未设置)),它可以工作并为我提供了Health和Sword变量,但是当 set 命令添加了该命令无效,如果有人知道解决方案,请告诉我,谢谢!

but if i maked a file like the above but removed the set (only Health=100 and Sword=Gold without set), it works and give me the variable Health and Sword, but when the set command added it didn't work, if any one knows solution please tell me and Thanks !

我想要一个命令给我变量,我不想只是从文件中删除 set 命令,因为如果我这样做了,保存蝙蝠文件的游戏将在从文件中提取变量以继续您离开游戏的位置时损坏.

I want a command that give me the Variables i don't want to just delete the set command from the file, because if i did that the game that saved the bat file will get corrupted while extracting the Variables from the file to continue where you left the game.

推荐答案

生成游戏的提示:

如果您要保留一个字符作为要保存的变量的前缀(例如,我要保存/重新加载的所有变量均以#开头),则只需保存一个游戏是

If you reserve a character as a prefix for variables-you-want-to-save (eg all variables I want to save/reload start with #) then all you need to save a game is

set #>"mygamefile.txt"

而您需要重新加载一个游戏就是

for /f "usebackqdelims=" %%a in ("mygamefile.txt") do set "%%a"

要更改所有#变量(在重新加载游戏前很有用),请使用

To zap all # variables (useful before reloading a game) use

for /f "delims==" %%a in ('set # 2^>nul') do set "%%a="

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

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