The below is supposed to go through a folder containing jpgs and replace the filenames with nnnZ.jpg, skipping a number if the image is in landscape.
I've seen the examples at https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-if?view=powershell-7.1 and it doesn't look like there's a problem with syntax of the if statement or the condition ($w -gt $h), but the 'then' is being executed every time, even though all but one of the images in the folder are in portrait. The values of $w and $h are correct (per the echo) so I don't understand what is going wrong.
Edit: or are those values actually strings, and is that what the %s mean?
Get-ChildItem | foreach {
$w=$(magick identify -format '%w' $_)
$h=$(magick identify -format '%h' $_)
$flag="false"
if ($w -gt $h) {
$c++
$flag="true"
}
$newname = "$($c)Z.jpg".Padleft(8,'0')
Rename-Item $_ -NewName $newname
$c++
echo $w $h $flag $c
}