我正在写一个批处理文件。
在批处理文件的中间,我想让它在文件夹中打开2个文件。哪一个......可能是前两个,最后两个,无论如何都无关紧要。我这样做,所以我们的用户可以通过更长的批处理文件过程检查书中的一些图像。我想做这样的事情:
set book=12345
for /F in ('\\server\share\%book%\*.pdf') DO (
open the first PDF file in the folder
)
Repeat one time
感谢您的时间。
答案 0 :(得分:0)
您可以跟踪迭代次数,并在达到限制时退出循环。
:: Enable delayedexpansion so we can use variables in the for loop
setlocal enabledelayedexpansion
set book=12345
set count=0
for %%F in (*.pdf) DO (
REM - open the PDF file here
:: Increment count (/a does arithmetic addition)
set /a count=!count!+1
:: Exit loop if count is 2
if !count! == 2 goto after
)
:after