0

我试图让批处理文件从文本文件中读取特定行,并设置 NewHDLocation="then here is the text from the line in the txt",然后执行 2 次,这样我以后可以执行 %NewHDLocation% 和 % WOTinstalldir% 告诉命令该信息

我的代码示例:

for /F "skip=0 delims=" %%i in (Settings.txt) do if not defined NewHDLocation set "NewHDLocation=%%i"&goto next

:next
for /F "skip=1 delims=" %%i in (Settings.txt) do if not defined WOTinstalldir set "WOTinstalldir=%%i"&goto next2

:next2
@echo %NewHDLocation%
@echo %WOTinstalldir%
pause

最后 2 个 @echo 只是为了测试它是否从 txt 中获取信息,但它只是输出:

C:\WINDOWS\system32>for /F "skip=0 delims=" %i in (Settings.txt) do if not defined NewHDLocation set "NewHDLocation=%i"  & goto next
 delims=" was unexpected at this time.

C:\WINDOWS\system32>for /F "skip=1 delims=" %i in (Settings.txt) do if not defined WOTinstalldir set "WOTinstalldir=%i"  & goto next2

C:\WINDOWS\system32>if not defined WOTinstalldir set "WOTinstalldir=ECHO is on."  & goto next2
ECHO is on.
ECHO is on.

C:\WINDOWS\system32>pause
Press any key to continue . . .

在我需要从我写的文本文件中读取(仅用于测试):

New_HDfiles_Drive
WOT_Install_Location
4

1 回答 1

2

在这种特殊情况下,我可能只是将文件流式传输到代码块中。

@ECHO OFF
<settings.txt (
set /p "NewHDLocation="
set /p "WOTinstalldir="
)

echo %NewHDLocation%
echo %WOTinstalldir%
pause
于 2018-07-25T16:26:59.427 回答