且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

变量未设置

更新时间:2022-12-04 15:34:23

您的/f 的,带有 tokens = * ,它正在读取整行而不进行拆分.

Your for /f, with a tokens=* is reading the full line without splitting it.

由于逗号是分隔符,因此您可以使用嵌套的 for 循环

As the comma is a delimiter, you can split the line with a nested for loop

setlocal enabledelayedexpansion
for /F "tokens=*" %%A in (%%~dpc\Report.txt) do (
    for %%x in (%%A) do (
        SET /A "vidx=vidx + 1"
        set "var!vidx!=%%x"
    )
)
set var

或者,要直接使用/f 进行拆分,您需要在需要检索的行中指示标记

Or, to directly split using the for /f you need to indicate the tokens in the line that you need to retrieve

for /F "tokens=1-4 delims=," %%A in (%%~dpc\Report.txt) do (
    set "var1=%%A"
    set "var2=%%B"
    set "var3=%%C"
    set "var4=%%D"
)
set var