如何改进我的 Windows 批处理文件,将两个 PDF 合并到一个单独的文件夹中,以便移动 PDF,无论是否存在合并

如何改进我的 Windows 批处理文件,将两个 PDF 合并到一个单独的文件夹中,以便移动 PDF,无论是否存在合并

我有一个 Windows 批处理文件,它可以合并两个不同文件夹中的 PDF 并将它们转储到第三个文件夹中。其中一个 PDF 是地图调查的 PDF,另一个是测量员拍摄的任何附带照片。截至目前,批处理文件仅移动它能够合并的文件,但我希望将第一页地图调查移动到其他文件夹,无论它是否带有附带照片。

所以我的问题是,我是否可以在下面的代码中添加一行,将 PDF 从“ sourcemap”目录中移动,而不管“ sourcetables”目录是否有匹配的文件。

下面是我的代码:

@echo off && setlocal enabledelayedexpansion

set "pdffile="
set "pdfattach="

set "pdftk=C:\Program Files (x86)\PDFtk\bin\pdftk.exe"
set "sourcemap=C:\GIS\Maps\Ranch Map Staging Folders\PCA\Central"

set "sourcetables=C:\GIS\Maps\Ranch Map Staging Folders\PCA\Photos"
set "destination=C:\GIS\Maps\Ranch Map Staging Folders\PCA\Central Completed"

set "gisfolder=C:\GIS\Maps\Ranch Map Staging Folders\PCA\Central Completed"
set "spfolder=\\sunpacific.local\lerdodata\Sun Pacific Public\6 - Business Units\Sun Pacific Farming Cooperative\B - General\10 - Maps\Ranch Maps\Other Maps\PCA\Maps\Central"
set "archivefolder=\\sunpacific.local\lerdodata\Sun Pacific Public\6 - Business Units\Sun Pacific Farming Cooperative\B - General\10 - Maps\Other Maps\PCA\Old Maps\Central"

for /f "delims=" %%i in ('dir /b /a-d /o:n "!sourcemap!\*.pdf"') do (
     set "pdffile=!sourcemap!\%%~i"
     set "pdfattach=!sourcetables!\PestManagement_TableSeries_!pdffile:~50!"
     set "outputpdf=%%~ni"
     "!pdftk!" "!pdffile!" "!pdfattach!" cat output "!destination!\!pdffile:~50,-4! - Field Scout Survey Map !date:~-4,4!!date:~-10,2!!date:~-7,2!.pdf"
     echo "Successfully completed !pdffile:~50,-4!"
    )

move "!spfolder!\*.pdf" "!archivefolder!"
move "!gisfolder!\*.pdf" "!spfolder!"

cmd /k

答案1

@echo off && setlocal enabledelayedexpansion

set "_pdftk=%ProgramFiles(x86)%\PDFtk\bin\pdftk.exe"
set "_date=!date:~-4,4!!date:~-10,2!!date:~-7,2!"
set "_str= - Field Scout Survey Map !_date!"

set "_tbl=C:\GIS\Maps\Ranch Map Staging Folders\PCA\Photos"
set "_map=C:\GIS\Maps\Ranch Map Staging Folders\PCA\Central"
set "_dst=C:\GIS\Maps\Ranch Map Staging Folders\PCA\Central Completed"

set "_arcDir=\\sunpacific.local\lerdodata\Sun Pacific Public\6 - Business Units\Sun Pacific Farming Cooperative\B - General\10 - Maps\Other Maps\PCA\Old Maps\Central"
set "_spDir=\\sunpacific.local\lerdodata\Sun Pacific Public\6 - Business Units\Sun Pacific Farming Cooperative\B - General\10 - Maps\Ranch Maps\Other Maps\PCA\Maps\Central"

for /f "delims=" %%i in =;(' dir /b /a-d /o:n "!_map!\*.pdf" ');= do =;(
     set "_pdf=%%~dpnxi" & set "_outputpdf=%%~nxi"
     if exist "!_tbl!\PestManagement_TableSeries_!_pdf:~50!.pdf" =;(
         call set "_photo=!_tb!\PestManagement_TableSeries_!_pdf:~50!.pdf"
         call "!_pdftk!" "!_pdf!" "!_photo!" cat output "!_dst!\!_pdf:~50,-4!!_str!.pdf"
        );= else copy /y "!_pdf!" "!_dst!\!_pdf:~50,-4!!_str!.pdf"
     call set "_pdf=" & call set "_photo=" & call set "_outputpdf="
     call echo/Successfully completed: "!_pdf:~50,-4!"
    );=

2>nul =;( move /y "!_spDir!\*.pdf" "!_arcDir!" & move /y "!_dst!\*.pdf" "!_spDir!"
    );= & timeout -1 | echo/Press any key to exit... & endlocal & exit /b 

只需测试:

if the photo file exists so execute (
  cat command this_file_pdf + this_file_photo ...
) else cat this_file_pdf ...

正如原帖所说音乐2年...但你测试文件的存在


请注意,鉴于我的语言难度/限制,可能需要进行一些调整,请测试并让我知道结果和/或任何其他调整......

相关内容