Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 将文件列表保存在变量中_Batch File_Batch Processing - Fatal编程技术网

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%