Batch file 将文件列表保存在变量中
我需要创建一个如下所示的变量字符串,作为参数传递给软件Batch file 将文件列表保存在变量中,batch-file,batch-processing,Batch File,Batch Processing,我需要创建一个如下所示的变量字符串,作为参数传递给软件 "filename:file1.txt|file2.txt|file3.txt" 我知道我需要以这种方式使用FOR循环 FOR %%i in (*.txt) DO 但我不知道如何将信息保存在同一个变量中。如果可以不在外部文件中传递详细信息,我更愿意这样做。将字符串附加到变量:set var=%var%new 您需要在循环中执行此操作: setlocal enabledelayedexpansion set "list=" FOR %%i
"filename:file1.txt|file2.txt|file3.txt"
我知道我需要以这种方式使用FOR循环
FOR %%i in (*.txt) DO
但我不知道如何将信息保存在同一个变量中。如果可以不在外部文件中传递详细信息,我更愿意这样做。将字符串附加到变量:
set var=%var%new
您需要在循环中执行此操作:
setlocal enabledelayedexpansion
set "list="
FOR %%i in (*.txt) DO set "list=!list!|%%i"
rem remove the first pipe symbol:
set list="%list:~1%"
echo %list%