Reputation: 3
I'm trying to write a simple batch script to use identify (from ImageMagick) to check dimensions of files in this directory and decide its orientation. Later, I'll be adding moving them to seperate folders. The problem is it can't enter the for loop.
setlocal enabledelayedexpansion
@echo off
for /r %%F in (*.) do (
identify -format "%%w" %%F > temp.txt
set /P temps=<temp.txt
set /A w=%temps%
identify -format "%%h" %%F > temp.txt
set /P temps=<temp.txt
set /A h=%temps%
if /I "%w%" GEQ "%h%" echo Is Landscape
if /I "%w%" LEQ "%h%" echo Is Vertical
pause
)
pause
Upvotes: 0
Views: 77
Reputation: 207465
You can make identify
tell you the width and height in a single call for all files in the directory, rather than calling it twice for each and every file:
identify -format "%w %h %f\r\n" *.png
1024 768 a.png
10 10 b.png
So, you can pair that up with your script and do it this way faster and more succinctly:
@ECHO OFF
REM Get dimensions and names of all files in one go
FOR /F "tokens=1-3 delims=+" %%A in ('identify -format "%%w+%%h+%%f\r\n" *.png') DO (
REM %%A is width, %%B is height, %%C is name
ECHO %%A,%%B,%%C
)
Upvotes: 1