Combine all PDFs in a folder and give new file name after folder?

I need help to come up with a script that will save me weeks of work.
I have 4000 folders with PDF files. Every one of the folders contain between 1 and 20 individual PDF files.
I want all PDFs in one folder combined to one file, then renamed after their parent folder, then saved to a separate target folder.

example:
folder1003 contains 15 PDFs. They should be combined into one file and saved as a new PDF file called “folder1003.pdf”
folder1004 contain 3 PDFs. They should be combined into one file and saved as a new PDF file called “folder1004.pdf”
Continue this until all 4000 folders are processed.

I am on snow leopard.

Any ideas on how to achieve this would be more than welcome:)

Oystein

Hi Oystein,

joinPDF still runs in lion, so it should in snow leo:
http://download.cnet.com/joinPDF/3000-18483_4-36691.html?tag=mncol;1

if installed try this:


global targetFolder


set targetFolder to (choose folder with prompt "please select a Targetfolder")
set sourceFolder to (choose folder with prompt "please select a Sourcefolder")

set sourceList to list folder sourceFolder without invisibles

my doStuff(sourceFolder, sourceList)

on doStuff(theFolder, aList)
	
	set mergeList to {}
	repeat with i from 1 to count of aList
		set aItem to alias ((theFolder as text) & item i of aList)
		if folder of (info for aItem) is true then
			set NewList to list folder aItem without invisibles
			set newFolder to aItem
			
			my doStuff(newFolder, NewList)
		else
			if type identifier of (info for aItem) is "com.adobe.pdf" then
				set end of mergeList to aItem
			end if
		end if
	end repeat
	
	my mergePDFs(theFolder, mergeList)
end doStuff


on mergePDFs(aFolder, toDoList)
	set theName to name of (info for aFolder)
	set MyJoinPDF to "joinPDF " & quoted form of POSIX path of ((targetFolder as text) & theName & ".pdf") & space
	repeat with i from 1 to count of toDoList
		set theFile to item i of toDoList
		set MyPosix to quoted form of POSIX path of theFile
		set MyJoinPDF to MyJoinPDF & MyPosix & space
	end repeat
	
	do shell script MyJoinPDF
end mergePDFs

Hope it’ll work …

Hans!
Thank you sooo much for your script!!! It works great on first attempt.
You are a life saver!

Danke sehr:)
Oystein