powershell

sethayes

·

Rename-Images

·

Powershell

·

Total Size: 970 B

·

·

Created: 1 month ago

·

Edited: 1 month ago

Function Rename-Images { Param ( $folders ) If ($null -ne $folders) { $folders = $folders | Get-Item } Else { $folders = Get-ChildItem "C:\Users\Seth\Downloads" -Directory | Where-Object {$_.Name -like "*X-Force*"} } ForEach ($folder in $folders) { $i = 0 $jpgs = @(Get-ChildItem "$($folder.FullName)") ForEach ($jpg in $jpgs) { $img = [Drawing.Image]::FromFile("$($jpg.FullName)") $width = $img.Width $height = $img.Height $img.Dispose() $prefix = "$($jpg.Directory.Name)" $iPath = "$($jpg.FullName)" If ($width -gt $height) { Rename-Item $iPath -NewName ("$($prefix)_{0:D2}-{1:D2}.jpg" -f $i++, $i++) -Force } Else { Rename-Item $iPath -NewName ("$($prefix)_{0:D2}.jpg" -f $i++) -Force } } } }

1 bit

21 views

Are you sure you want to delete?

User Profile Picture

I didn't realise Powershell was so... powerful! I must learn it