Mega PDFer med liknande namn till 1 fil

Permalänk
Medlem

Mega PDFer med liknande namn till 1 fil

Halloj!
Har googlat och sökt på forumet men lyckas ändå inte få till det. Behöver lite vägledning här.

Scenariot är följande:
Har en mapp med ett par tusen pdf filer med denna namngivning: XX1001-23.pdf, XX1001-27.pdf, XX1002-23.pdf, XX1002-27.pdf, XX1003-23.pdf, XX1003-27.pdf osv. Dessa vill jag kunna automatiskt merga till XX1001.pdf, XX1002.pdf och XX1003.pdf istället.

Har försökt denna metoden jag hittade:

Download pdftk (direct link here). Extract it somewhere. Put pdftk.exe and the batch together. Then open cmd where the batch is located* and run it. * (shift+RightClic open command prompt here) The script should works if the folder structure is like this: | +---111111 | 111111_ABCD.pdf | 111111_EFGH.pdf | +---123456 | 123456_ABCD.pdf | 123456_EFGH.pdf | 123456_IJKL.pdf | \---222222 222222_IJKL.pdf 222222_WXYZ.pdf And not in a single folder where all the files are there. @echo off setlocal enabledelayedexpansion rem source root folder where to crawl pdfs. set "source=c:\mydoc\pdf" rem destination folder set "destination=c:\mydoc\merged" for /f "delims=" %%a in ('dir /b /s /ad /o:n "%source%"') do ( set _pdffiles= for /f "delims=" %%i in ('dir /b /a-d /o:n "%%a\*.pdf"') do ( set _pdffiles=!_pdffiles! "%%i" set "_outputpdf=%%~ni" ) echo pdftk.exe !_pdffiles! cat output "%destination%\!_outputpdf:~0,6!.pdf" )

Men det händer inget alls.

Denna metod får jag att funka men det ju inte hela vägen fram:

@echo off setlocal enabledelayedexpansion FOR %%A IN (%*) DO (set command=!command! %%A) pdftk.exe %command% cat output "%~dp1binder.pdf"

Vill alltså kunna markera alla filer i mappen och merga med ett klick.

Tips?

Permalänk
Medlem

Nu är det väldigt nära. MEN får inte själva ihopslagningen att funka helt.

Nån ide?

@echo off setlocal enabledelayedexpansion rem source root folder = script folder set source=%~dp0 rem destination folder set "destination=%source%merged" echo !destination! for /f "delims=" %%a in ('dir /b /a-d /o:n "%source%"\*.pdf') do ( set x=%%a set "prefix=!x:~0,6!" if not "!last_prefix!" == "!prefix!" ( set _pdffiles= ) set _pdffiles=!_pdffiles! "%%a" if not "!last_prefix!" == "!prefix!" ( if not defined !last_prefix! ( pdftk.exe !_pdffiles! cat output "%destination%\!prefix:~0,6!.pdf" ) ) set "last_prefix=!prefix!" )