问题
I want to delete all *.jpg files in a specific folder and all its subfolders which have e.g. width unequal 800 and height unequal 600 (leaving only 800x600 jpg images).
Can someone tell me how to do this in Powershell?
I know I can remove *.jpg images with
Get-ChildItem -Path .\ -Filter *.jpg -Recurse | foreach ($_) {remove-item $_.fullname}
But I can't seem to find how to select height/width of an image.
回答1:
You could use the System.Drawing.Image
.NET Object:
$(Get-ChildItem -Filter *.jpg).FullName | ForEach-Object {
$img = [Drawing.Image]::FromFile($_);
$dimensions = "$($img.Width) x $($img.Height)"
If ($dimensions -eq "800 x 600") {
Remove-Item $_
}
}
来源:https://stackoverflow.com/questions/26314980/powershell-delete-images-of-certain-dimensions