?
Solved

Need help writing a batch file to process a list

Posted on 2009-02-23
5
Medium Priority
?
220 Views
Last Modified: 2013-11-10
At our company we have a lot of PDF's that should be merge into a single PDF by claim number.  What happens is when something is scanned in, the PDF is saved by claim # (eg, 1234567).  If more sheets are scanned for the same claim # the new PDF are named 1234567_0001, 1234567_0002, 1234567_0003, etc.

I've attached a batch file that uses PDFTK to merge the PDFs.  With this batch file, I have to enter the claim #s manually.  I have a list of claim numbers that need to be processed, is there a way I can pass this list into the batch file to automate the entering of claim #'s?

Thanks,
MG
:START
@cls
@REM Setting Variable
@set /p claim=Enter Claim#:
 
:MERGE
@REM Performing Merge
@pdftk %claim%*.pdf cat output %claim%.new
 
:DELETE
@REM Deleting Old Files
@del %claim%*.pdf
@ren %claim%.new %claim%.pdf
 
:RESTART
@set /p choice=Merge Another (Y/N)?
@IF '%choice%'=='Y' GOTO START
@IF '%choice%'=='y' GOTO START
 
:END

Open in new window

0
Comment
Question by:mguilmette
  • 3
5 Comments
 
LVL 7

Expert Comment

by:johnnash1180
ID: 23712582
Yes, you can.

Put all your claim numbers in a text file, say claims.txt.
The use the FOR command to read every claim number in the claims.txt file.
Then, the rest of the commands as it is.
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 23712662
Try this. Please copy your files to an alternate folder to make sure it does what you want it to.
@cls
FOR /f "Tokens=1 delims=_" %%c in (dir /b "C:\PDFFolder\*_*.pdf") do (
    @if exist %%c_*.pdf @pdftk %%c_*.pdf cat output %%c.new
@REM Deleting Old Files
    @del %%c_*.pdf
    @ren %%c.new %%c.pdf
)

Open in new window

0
 

Author Comment

by:mguilmette
ID: 23712768
I copied several examples that need to be merged into a folder called C:\test.  Below is the output I get when running AmazingTech's solution.


C:\Test>FOR /F "Tokens=1 delims=_" %c in (dir /b "C:\test\*_*.pdf") do (
if exist %c_*.pdf pdftk %c_*.pdf cat output %c.new



)
The system cannot find the file dir.

C:\Test>
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 23713590
OH. we need to either change directory or specify the folder
@cls
FOR /f "Tokens=1 delims=_" %%c in (dir /b "C:\Test\*_*.pdf") do (
    @if exist "C:\Test\%%c_*.pdf" @pdftk "C:\Test\%%c_*.pdf" cat output "C:\Test\%%c.new"
@REM Deleting Old Files
    @del "C:\Test\%%c_*.pdf"
    @ren "C:\Test\%%c.new" %%c.pdf
)

Open in new window

0
 
LVL 21

Accepted Solution

by:
AmazingTech earned 2000 total points
ID: 23714059
Some things you can try to see if the claim number is coming through properly.
FOR /f "Tokens=1 delims=_" %%c in (dir /b "C:\Test\*_*.pdf") do (
    @echo Claim number=%%c
)

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Screencast - Getting to Know the Pipeline

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question