script to join pdfs

I am looking for a script I can simply double click on, and it will join 2 pdfs that end with A.pdf and Q.pdf.
For instance in folder c:\files\... I have many files.
for example..


When is looks in this folder it will take file 12345A.pdf and file 12345Q.pdf and join them to form 12345.pdf
And it will delete 12345A.pdf and 12345Q.pdf

The script needs to look through the list and see if there are 2 same prefixes, however one ending with A.pdf and the other ending with Q.pdf and then join them.

I believe pdftk server will allow for joining however I am not sure if it can get this granular.

Thanks for your help.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase ExpertCommented:
Please use this script from old EE database itself. You may need to tweak if required.

@echo off
set /p fn=Enter the output filename:
pdftk *.pdf cat output %fn%.pdf
ren %fn%.pdf
del *.pdf
ren %fn%.pdf

Open in new window

Joe Winograd, Fellow&MVEDeveloperCommented:
Hi Pawan,
Thank you for the reference to my post — much appreciated — although the more relevant part for this question occurs later in that thread where it talks about merging files that have matching initial characters. Regards, Joe
100questionsAuthor Commented:
Thanks to you both.  Is what I am looking for possible?
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Joe Winograd, Fellow&MVEDeveloperCommented:
> Is what I am looking for possible?

Yes! Do all of the file names have just five characters before the A and Q? Are the characters before the A and Q always digits (numbers)? I'm leaving my office now for an hour or two and will check back for your answers to those questions when I return. Regards, Joe
100questionsAuthor Commented:
Thanks Joe, yes all the files have 5 characters, and the digits before the A and Q are always numbers.  Thanks so much.
Joe Winograd, Fellow&MVEDeveloperCommented:
> yes all the files have 5 characters, and the digits before the A and Q are always numbers

Another question: are there any files with the same five leading digits but do not have an A or Q next? For example, could there be three files like this:


Or will there always be just the two files (A and Q) with the same five leading digits, e.g.:


Regards, Joe
Joe Winograd, Fellow&MVEDeveloperCommented:
Hi 100questions (that feels so awkward...would be nice to be able to address you with a first name),

Haven't heard back from you on my last question, but I'm confident that one of the programs in my portfolio can help you. It is called CAPTAIN, which is an acronym for Combine All PDFs Together with Agreeing Initial Names. CAPTAIN is an enhancement of a program that I first discussed in my EE article, How to Combine-Merge PDF Files in Many Subfolders (which is an offshoot of my earlier EE article, How To Combine-Merge-Append a Large Batch of TIFF Files — both of which are programmed in the AutoHotkey language).

As stated at the article (both articles, actually), I removed the source code to make major changes to the program. My initial intention was to re-attach the source code there, but as mentioned in a more recent comment at the article, I've decided not to post the full program (I plan to rewrite the article as a "design roadmap" when I have some spare time). The "major changes" to that program have resulted in CAPTAIN, for which the Quick Start Guide is attached. Most of us don't like to read manuals, but I encourage you to read the Quick Start Guide — it's only four pages and will give you a good sense of what it can do.

If the answer to my last question is that there are only A and Q files, then CAPTAIN will work for you as is. You would simply run it with 5 as the number of leading characters that need to match. But if there are other files with the same leading 5 characters as the A and Q files, then CAPTAIN won't work for you as is, since it would combine those files, too (but I could tweak it to work for you).

I'm not ready yet for broad distribution of CAPTAIN, but let me know if it interests you and I'll get you a copy to try. Regards, Joe

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
100questionsAuthor Commented:
Hi Joe, thanks so much.  Yes, I would be willing to try.  thanks kindly.
Joe Winograd, Fellow&MVEDeveloperCommented:
You're welcome, 100questions. As I mentioned at your other similar question, I'm not ready yet for distribution of CAPTAIN to everyone on the Internet, so I sent you a PM via the EE Message system to discuss getting it to you on a test basis. Regards, Joe
Joe Winograd, Fellow&MVEDeveloperCommented:
Selected posts with reasons:

#a42388681: It's possible to make the code later in that thread work, so this post deserves credit.

#a42394779: I guarantee that the CAPTAIN program can do exactly what's requested in this question. The program has many users, all with the same requirement as this question, and all reporting success with it.

Splitting the points evenly between the two experts.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.