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 批处理文件以打开文件夹中X个文件_Batch File_For Loop - Fatal编程技术网

Batch file 批处理文件以打开文件夹中X个文件

Batch file 批处理文件以打开文件夹中X个文件,batch-file,for-loop,Batch File,For Loop,我正在写一个批处理文件 在批处理文件的中间,我想让它在文件夹中打开2个文件。不管是哪一个。。可能是前两个,最后两个,随便什么。我这样做是为了让我们的用户可以通过更长的批处理文件过程来检查书中的一些图像。我想这样做: set book=12345 for /F in ('\\server\share\%book%\*.pdf') DO ( open the first PDF file in the folder ) Repeat one time 谢谢您的时间。您可以跟踪迭代次数,并在达到极限

我正在写一个批处理文件

在批处理文件的中间,我想让它在文件夹中打开2个文件。不管是哪一个。。可能是前两个,最后两个,随便什么。我这样做是为了让我们的用户可以通过更长的批处理文件过程来检查书中的一些图像。我想这样做:

set book=12345
for /F in ('\\server\share\%book%\*.pdf') DO (
open the first PDF file in the folder
)
Repeat one time

谢谢您的时间。

您可以跟踪迭代次数,并在达到极限时退出循环

:: 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

好极了非常感谢你。