0

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
Osa
  • 3
  • 3
  • 2
    besides you need [delayed expansion](http://stackoverflow.com/a/30284028/2152082) inside your `for` loop - how do you know, you "can't enter" it? – Stephan May 10 '16 at 08:54
  • Checked, when I just have nothing but pause inside it wont pause. So nothing inside it isnt executed. – Osa May 10 '16 at 09:16
  • 2
    that should mean, it didn't find any files without extension. Are there any? – Stephan May 10 '16 at 09:52
  • Do you know what the file mask `*.` means? it matches files without extension; to match *all* files, use `*.*` or `*`... – aschipfl May 10 '16 at 10:56
  • That was the problem, typos... Thanks alot. – Osa May 10 '16 at 11:43

1 Answers1

1

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
)
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432