Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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
Windows批处理脚本-文件迭代问题_Windows_Batch File_Command Line - Fatal编程技术网

Windows批处理脚本-文件迭代问题

Windows批处理脚本-文件迭代问题,windows,batch-file,command-line,Windows,Batch File,Command Line,我想一次一个地从多个文件中读取输入,并在转到下一个文件之前处理该输入。所有文件都有一个定义其输入顺序的特殊名称。具体内容如下:订单。我认为批处理文件中的以下代码允许我按照for循环指定的顺序读取它们,但它没有做任何事情。有人能看出这个错误吗?我在.bat文件中有以下内容: @echo off for %%a in (20, 40, 80) do ( for %%b in (80, 160) do ( for /l %%c in (1,1,3) do ( for /l %%d in (1,1,10

我想一次一个地从多个文件中读取输入,并在转到下一个文件之前处理该输入。所有文件都有一个定义其输入顺序的特殊名称。具体内容如下:订单。我认为批处理文件中的以下代码允许我按照for循环指定的顺序读取它们,但它没有做任何事情。有人能看出这个错误吗?我在.bat文件中有以下内容:

@echo off
for %%a in (20, 40, 80) do (
for %%b in (80, 160) do (
for /l %%c in (1,1,3) do (
for /l %%d in (1,1,10) do (
for /l %%e in (1,1,6) do (
for /l %%f in (0,1,6) do ( 
if %%e LSS %%f (
if exist ordersheet_%%a_%%b_%%d echo "  " %%e %%f >> output.txt
if exist ordersheet_%%a_%%b_%%d START ThesisVelo.exe distancematrix_%%a.txt ordersheet_%%a_%%b_%%d %%c %%d %%e %%f >> output.txt
)
)
)
)
)
)
)

下面的批处理文件实现了与原始代码相同的处理过程,但它有一些小的修改,使代码更清晰,并显示了已处理文件的名称。请注意,我不知道你的代码应该实现什么

@echo off
setlocal EnableDelayedExpansion
for %%a in (20  40  80) do (
   for %%b in (80  160) do (
      for /l %%c in (1,1,3) do (
         for /l %%d in (1,1,10) do (
            for /l %%e in (1,1,6) do (
               rem Just process values of %%f greater than %%e
               set /A f=%%e+1
               for /l %%f in (!f!,1,6) do (
                  echo ordersheet_%%a_%%b_%%d c=%%c, d=%%d, e=%%e, f=%%f
                  if exist ordersheet_%%a_%%b_%%d (
                     echo "  " %%e %%f >> output.txt
                     START ThesisVelo.exe distancematrix_%%a.txt ordersheet_%%a_%%b_%%d %%c %%d %%e %%f >> output.txt
                  )
               )
            )
         )
      )
   )
)
输出的某些部分:

ordersheet_20_80_1 c=1, d=1, e=1, f=2
ordersheet_20_80_1 c=1, d=1, e=1, f=3
ordersheet_20_80_1 c=1, d=1, e=1, f=4
ordersheet_20_80_1 c=1, d=1, e=1, f=5
ordersheet_20_80_1 c=1, d=1, e=1, f=6
ordersheet_20_80_1 c=1, d=1, e=2, f=3
ordersheet_20_80_1 c=1, d=1, e=2, f=4
ordersheet_20_80_1 c=1, d=1, e=2, f=5
ordersheet_20_80_1 c=1, d=1, e=2, f=6
ordersheet_20_80_1 c=1, d=1, e=3, f=4
ordersheet_20_80_1 c=1, d=1, e=3, f=5
ordersheet_20_80_1 c=1, d=1, e=3, f=6
ordersheet_20_80_1 c=1, d=1, e=4, f=5
ordersheet_20_80_1 c=1, d=1, e=4, f=6
ordersheet_20_80_1 c=1, d=1, e=5, f=6

ordersheet_20_80_2 c=1, d=2, e=1, f=2
. . .
ordersheet_20_80_2 c=1, d=2, e=5, f=6

ordersheet_20_80_3 c=1, d=3, e=1, f=2
. . .
ordersheet_20_80_3 c=1, d=3, e=5, f=6

ordersheet_20_80_4 c=1, d=4, e=1, f=2
. . .
ordersheet_20_80_4 c=1, d=4, e=5, f=6

ordersheet_20_80_5 c=1, d=5, e=1, f=2
. . .
ordersheet_20_80_5 c=1, d=5, e=5, f=6

ordersheet_20_80_6 c=1, d=6, e=1, f=2
. . .
ordersheet_20_80_6 c=1, d=6, e=5, f=6

ordersheet_20_80_7 c=1, d=7, e=1, f=2
. . .
ordersheet_20_80_7 c=1, d=7, e=5, f=6

ordersheet_20_80_8 c=1, d=8, e=1, f=2
. . .
ordersheet_20_80_8 c=1, d=8, e=5, f=6

ordersheet_20_80_9 c=1, d=9, e=1, f=2
. . .
ordersheet_20_80_9 c=1, d=9, e=5, f=6

ordersheet_20_80_10 c=1, d=10, e=1, f=2
. . .
ordersheet_20_80_10 c=1, d=10, e=5, f=6


The same block above with c=2 and c=3 until:
ordersheet_20_80_10 c=3, d=10, e=5, f=6



The same whole block above, from:
ordersheet_20_160_1 c=1, d=1, e=1, f=2
until:
ordersheet_20_160_10 c=3, d=10, e=5, f=6




The same whole block above, from:
ordersheet_40_80_1 c=1, d=1, e=1, f=2
until:
ordersheet_40_160_10 c=3, d=10, e=5, f=6



The same, from:
ordersheet_80_80_1 c=1, d=1, e=1, f=2
until:
ordersheet_80_160_10 c=3, d=10, e=5, f=6

很好,但是您应该从代码中解释更多内容。例如,要读取的第一个文件应该是ordersheet_20_80_1,第二个ordersheet_20_80_2,依此类推。无论如何,我认为我在%或其他方面做错了什么..没有运行此批处理的目录示例,这是盲目猜测。但是-假设目标文件存在,
%%e
将从1-6运行,
%%f
将从0-6运行。在您的测试中,
%%f
=0或1和
%%e
=6永远无法输入
(如果存在)语句。啊,您说得对,谢谢!一般来说,我对编程了解不多,所以如果我遗漏了有用的信息,我很抱歉。但是,我知道.exe工作正常,即使%%e从未访问过。但是,当我尝试通过此批处理文件输入订单时,什么也没有发生。非常感谢Aacini,这对我非常有用!我不会详细解释,但是,这段代码是用来测试自行车共享系统的VRP程序的。实际上,我现在遇到了另一个问题。例如,我将文件ordersheet_20_80_1添加到包含.bat和.exe文件的映射中。但是,当我执行.bat文件时,如果存在订单单\%a \%b \%d(
),这一行似乎永远不会为真?