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

Batch file to open X number of files in a folder

我正在写一个批处理文件。

在批处理文件的中间,我想让它打开文件夹中的 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