hello everyone,
I want to loop through pdf files, find the ones that are portrait, and move them to a seperate folder.
pdftk is an executable that gives me this information, so when i type
for /f "tokens=2" %%a in ('pdftk %%g dump_data ^| find "PageMediaDimensions"') do (
set /a dim1=%%a
)
dim1 represents one of the dimensions and dim2 the other.
That part works well.
After, I just have to compare dim1 and dim2 to see if %dim1% GTR %dim2%, and if it is, move the file to the appropriate Folder
But... it doesn't work. I think the problem comes from using dim1 inside a for loop, it is not seen as a number
Any ideas ?
Thanks,
Audrey
for %%g in (*.pdf) do (
for /f "tokens=2" %%a in ('pdftk %%g dump_data ^| find "PageMediaDimensions"') do (
set /a dim1=%%a
)
for /f "tokens=3" %%b in ('pdftk %%g dump_data ^| find "PageMediaDimensions"') do (
set /a dim2=%%b
)
if %dim1% GTR %dim2% (
move %%g myFolder
)
)
if condition inside a for loop
Moderator: DosItHelp
Re: if condition inside a for loop
Try this - see if the echo command shows the two items correctly before removing the echo and pause:
Your problem was essentially that variables can't be set or changed within a for loop unless you use
setlocal enabledelayedexpansion and !variable! syntax.
Code: Select all
@echo off
for %%g in (*.pdf) do (
for /f "tokens=2,3" %%a in ('pdftk "%%g" dump_data ^| find "PageMediaDimensions" ') do (
echo if %%a GTR %%b move "%%g" "myFolder"
pause
)
)
Your problem was essentially that variables can't be set or changed within a for loop unless you use
setlocal enabledelayedexpansion and !variable! syntax.
Re: if condition inside a for loop
Hell Foxidrive,
That's what i see :
if 1191 GTR 842 move "doc1.pdf" "myFolder"
Press any key to continue . . .
if 842 GTR 1191 move "doc2.pdf" "myFolder"
Press any key to continue . . .
Nothing seems to happen i'm afraid...
That's what i see :
if 1191 GTR 842 move "doc1.pdf" "myFolder"
Press any key to continue . . .
if 842 GTR 1191 move "doc2.pdf" "myFolder"
Press any key to continue . . .
Nothing seems to happen i'm afraid...
Re: if condition inside a for loop
Remove the ECHO command.
Re: if condition inside a for loop
Thanks everyone !
It works.
It works.