如何批量读取txt中的行.如何将每一行放在自己的变量中?

1 batch-file

我需要在我的文本中的每一行都有自己的变量.像这样:

文本文件:

TEMPLATE: Permission, Username, Password;
Admin, Admin, Superflip;
User, Mom, Hi;
Run Code Online (Sandbox Code Playgroud)

我希望此文件中的每一行都在其OWN变量中.可能吗?

BDM*_*BDM 5

以下应该工作......

@echo off & setlocal enabledelayedexpansion
set num=0
::Change "File_Path" to where your file is. If it is in the same directory, just put the name.
for /f "delims=" %%i in (File_Path) do (
    set /a num+=1
    set line[!num!]=%%i
)
Run Code Online (Sandbox Code Playgroud)

脚本的工作原理:该变量num设置为在for循环中使用.所述for环穿过文件中的每一行File_Path设置的线line,由多个后缀.

此脚本模拟创建数组.要调用特定的行,请执行%line[number_of_line]%.例如,检查line 3line 5是相同的,你会放像

if %line[3]%==%line[5]% echo Line 3 and 5 are the same.
Run Code Online (Sandbox Code Playgroud)