0

I am trying to write a batch file which searches for pdf files and finds how many pages they have and loop all pages.

I wrote the following. I can find the files, I can even find the pagecounts with a tool named pdftk. The results is as below.

C:\Users\test\Documents\fishes\Fish_1.pdf
NumberOfPages: 5

How can I set a variable which has the value of 5?

@ECHO off
for /R %%i IN (*.pdf) DO (

ECHO %%i
"C:\Program Files (x86)\PDF Labs\PDFtk Server\bin\pdftk.exe" %%i dump_data | findstr NumberOfPages

set pagecount = findstr NumberOfPages ???

FOR /L %%j IN (1,1,%pagecount%) DO (
    ECHO "page " + %%j
)

)

1 Answer 1

1

You were already 90% there. Use the FOR /F command to process the results of a command. Type HELP FOR from the command prompt for more info.

for /f "tokens=2" %%A in (
  '"C:\Program Files (x86)\PDF Labs\PDFtk Server\bin\pdftk.exe" %%i dump_data ^| findstr NumberOfPages'
) do set numberOfPages=%%A
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.