批处理文件 - 文本文件 打印命令

Batch file - text file Printing order

我在一个文件夹中有大约 100 个文本文件 temp_files,这就是我打印它们的方式

        for /f %%B in ('dir temp_files\*.txt /b') do (

    start /min notepad /P temp_files\%%B
    )

文件打印正常,但打印顺序不对。例如,当我像这样回显输出时

        for /f %%B in ('dir temp_files\*.txt /b') do (

    echo start /min notepad /P temp_files\%%B>>print_order.txt
    )

在print_oreder.txt中顺序正确, 这是 print_order.txt 的样子:

start /min notepad /P temp_files\location_1_product_1.txt
start /min notepad /P temp_files\location_1_product_2.txt
start /min notepad /P temp_files\location_1_product_3.txt
start /min notepad /P temp_files\location_2_product_1.txt
start /min notepad /P temp_files\location_2_product_2.txt
start /min notepad /P temp_files\location_2_product_3.txt

但实际打印出来时,它不是按顺序排列的,是随机排列的。这就是实际打印的方式, 实际打印顺序

location_1_product_1.txt
location_1_product_3.txt
location_2_product_2.txt

有没有什么办法可以按这样的顺序打印, 期待打印顺序:

location_1_product_1.txt
location_1_product_2.txt
location_1_product_3.txt
location_2_product_1.txt
location_2_product_2.txt
location_2_product_3.txt

请帮忙。谢谢。

您遇到了计时问题(您打开了大约 100 个进程,不能保证它们按特定顺序执行)。添加一个 /wait 以等待每个进程完成后再开始下一个进程:

start /min /wait notepad /P temp_files\%%B

(注意:这会使您的脚本变慢,但无论如何您都必须等待打印机..)