I am writing a batch script around the qpdf executable. The end goal is to be able to drag and drop PDF files on the batch script and process each PDF using qpdf.exe.
I have managed to write a batch script to accept the drag and drop of multiple files (Hopefully a folder full of files later) and loop through all of the files printing the file to the screen.
I have been unable to get the batch script to execute the qpdf command so far. I think my problem is the qpdf command line switches, they use "--" instead of "/". Also, the use of spaces and punctuation is present in the file paths and names. (Thank you end users who don't listen. You know who you are.)
I will attach the script I have so far.
If someone could help me understand what I am doing wrong, I would greatly appreciate it.
@ECHO off
REM For each argument (file in my case)
FOR %%a IN (%*) DO (
REM If the path turns out to be a folder
IF EXIST %%a\* (
ECHO Skipping directory
ECHO %%a
ECHO;
REM If not a folder
) ELSE (
ECHO %%a was dropped on me
ECHO;
REM This is the command to be run
REM qpdf.exe --rotate=+180 --replace-input "C:\Users\user\desktop\SO-005553 7-2-2020.pdf"
REM
REM define the executable path and executable and command switches and input file
REM %~dp0 is file path of this script
REM qpdf.exe is executable
REM $$~a is the input file
SET command=""%~dp0qpdf.exe"" --rotate=+180 --replace-input ""%%~a""
ECHO %command%
ECHO;
START "" %command%
)
)
PAUSE
For some reason, %command% will not echo or execute.
It appears to be empty.
However, if I turn @ECHO on, I can see that the set command is correct.
I have tried 3 different ways to execute the command.
One of them threw a fit about the command not found, one of them opened a command window, and this one appears to do nothing.