Passing arguments to a subroutine
Posted: 06 Nov 2022 01:03
How can I fix code snippet A? Thanks!
Code snippet A
This does not work:
Code snippet B
This works:
Code snippet C
This works:
Code snippet A
This does not work:
Code: Select all
SET pwd=mypassword
SET files_path=C:\Users\User\Downloads\_bat testing\*.pdf
SET qpdf_path=C:\Program Files\qpdf 11.1.1\bin\qpdf.exe
for %%G in ("%files_path%") do (CALL :subroutine "%qpdf_path%" %pwd% "%%G")
:subroutine
%1 --decrypt --password=%2 "%3" "%~n3_unlocked%~x3"
GOTO :eof
This works:
Code: Select all
setlocal disableDelayedExpansion
for %%G in ("C:\Users\User\Downloads\_bat\*.pdf") do (CALL :subroutine "%%G")
:subroutine
"C:\Program Files\qpdf 11.1.1\bin\qpdf.exe" --decrypt --password=mypassword "%1" "%~n1_unlocked%~x1"
GOTO :eof
This works:
Code: Select all
SET pwd=mypassword
SET files_path=C:\Users\User\Downloads\_bat testing\*.pdf
SET qpdf_path=C:\Program Files\qpdf 11.1.1\bin\qpdf.exe
setlocal disableDelayedExpansion
for %%G in ("%files_path%") do (
set name=%%~nG
set ext=%%~xG
setlocal enableDelayedExpansion
"%qpdf_path%" --decrypt --password=%pwd% "%%G" "!name!_unlocked!ext!"
endlocal
)