Batch file 将PDF与PDFTK和相同的起始文件名合并
我试图使用pdftk来搜索一个目录中类似的文件名,并将它们组合起来 我发现了一个由Aacini编写的很棒的脚本,它与格式名称_KM_1、名称_KM_2、名称_KM_3等一起使用时效果非常好。它会将所有包含KM的文件合并成pdf 在我的场景中,我的文件名都以类似于Q1111_确认、Q1111_顺序、Q2222_确认、Q2222_顺序的内容开头。我将如何修改此项以合并订单/确认与Qnumber匹配?我尝试了几种不同的方法,但没有成功Batch file 将PDF与PDFTK和相同的起始文件名合并,batch-file,Batch File,我试图使用pdftk来搜索一个目录中类似的文件名,并将它们组合起来 我发现了一个由Aacini编写的很棒的脚本,它与格式名称_KM_1、名称_KM_2、名称_KM_3等一起使用时效果非常好。它会将所有包含KM的文件合并成pdf 在我的场景中,我的文件名都以类似于Q1111_确认、Q1111_顺序、Q2222_确认、Q2222_顺序的内容开头。我将如何修改此项以合并订单/确认与Qnumber匹配?我尝试了几种不同的方法,但没有成功 @echo off setlocal EnableDelayedE
@echo off
setlocal EnableDelayedExpansion
rem Initialize (delete) "lastFile" and "fileList" variables
set "lastFile="
set "fileList="
rem Next line get the output of a "dir /B" command, that show file names
*only*
rem "for /F" command execute the dir, get the output and divide each line in
two "tokens" ("%%a" and "%%b")
rem with the first part before the "_" in "%%a" and the *rest* (including f
urther "_") in "%%b"
for /F "tokens=1* delims=_" %%a in ('dir /B *_KM_*.*') do (
rem If the base file name changed...
if "%%a" neq "!lastFile!" (
rem Process previous file list;
rem this "if" is just to avoid process the empty list the first time
if defined fileList (
pdftk !fileList! output !lastFile!.pdf
)
rem Reinitialize the new list
set "lastFile=%%a"
set "fileList=%%a_%%b"
) else (
rem Append this file to current list
set "fileList=!fileList! %%a_%%b"
)
)
rem Process the last list
pdftk !fileList! output !lastFile!.pdf
有人能帮忙吗?有人能帮忙吗?
@echo off
setlocal EnableDelayedExpansion
rem Initialize (delete) "lastFile" and "fileList" variables
set "lastFile="
set "fileList="
rem Next line get the output of a "dir /B" command, that show file names *only*
rem "for /F" command execute the dir, get the output and divide each line in two "tokens" ("%%a" and "%%b")
rem with the first part before the "_" in "%%a" and the *rest* (including further "_") in "%%b"
for /F "tokens=1* delims=_" %%a in ('dir /B ***.*') do (
rem If the base file name changed...
if "%%a" neq "!lastFile!" (
rem Process previous file list;
rem this "if" is just to avoid process the empty list the first time
if defined fileList (
pdftk !fileList! output !lastFile!.pdf
)
rem Reinitialize the new list
set "lastFile=%%a"
set "fileList=%%a_%%b"
) else (
rem Append this file to current list
set "fileList=!fileList! %%a_%%b"
)
)
rem Process the last list
pdftk !fileList! output !lastFile!.pdf