For loop statement in batch program repeats 5 times -
but i'm still having issue regards program posted previously. think there problem in loop statement because after opened file "passwords.csv", noticed loop repeated 5 times.
the first record r_000100.pdf assigned password 8337, repeated in other rows , reassigned other random passwords. , when tried open pdf file, seems last random password assigned (which 13429) password, , not 8337.
what should correct program wherein after pdf files have been combined , assigned passwords, program stop loop , exit? having 1 entry in output file "passwords.csv" , won't repeat 5 times.
below complete batch program accomplished, of peter wright.
@echo off setlocal enabledelayedexpansion /f "tokens=1,2 delims=abcdef_." %%i in ('dir *.txt *.pdf /b') ( txttopdf a_%%i.txt a_%%i.pdf -pps4 -pfs10.9 txttopdf b_%%i.txt b_%%i.pdf -pps4 -pfs8.9 txttopdf c_%%i.txt c_%%i.pdf -pps4 -plm50 -prm50 -pfs7.9 txttopdf d_%%i.txt d_%%i.pdf -pps4 -plm60 -prm60 -pfs8.9 txttopdf e_%%i.txt e_%%i.pdf -pps5 -pot -pfs10 txttopdf f_%%i.txt f_%%i.pdf -pps5 -pot -pfs12 set pass=!random! pdftk *%%i.pdf cat output pdf\r_%%i.pdf user_pw !pass! echo %%i r_%%i.pdf !pass! >> passwords.csv ) echo *************************************************** echo * * echo * pdf reports generated. * echo * please type exit @ command prompt. * echo * * echo *************************************************** pause exit
easy, have give batch file logic realise line to.
replace :
for /f "tokens=1,2 delims=abcdef_." %%i in ('dir *.txt *.pdf /b') (
with :
set /a count=0 /f "tokens=1,2 delims=abcdef_." %%i in ('dir *.txt *.pdf /b') ( set /a count+=1 if !count! equ 1 (
note : add bracket when closing for-loop if-loop
this way, count each line for-loop parse's. if want set password second or fifth line, replace if !count! equ 1 (
if !count! equ 2 (
or if !count! equ 5 (
respectively.
it useful in batch files when using for-loops. done default when using actual programming language.
hope helped.
yours mona
Comments
Post a Comment