File name enumeration (000-999)

For years I’ve used Ant Renamer in my photo processing workflow to pretty things up and keep things nice and organized. If you prefer a minimal user interface, check it out, it’s dope. If you would rather handle the tweaks with some PowerShell magic, then keep reading.

Overview, this will go through all the .jpg files in the defined directory and start naming them accordingly with some variables you define.

$date = Get-Date -Format 'MM-dd-yy'
$basefilename = "testing this hooya deal script"
$filepath = "C:\temp\yada"
$filetype = ".jpg"
$files = Get-ChildItem $filepath\*$filetype -File

$i = 1
$files | ForEach-Object {
    Rename-Item $_ -NewName ("$date $basefilename {0:D3}$filetype" -f $i++).Replace(' ','-')
}
This is what the script would produce.

File name string replacement

An occasional requirement is to replace a string of text within the file names already.

$filepath = "C:\temp\yada"
$files = Get-ChildItem $filepath -File

$oldstring = "testing"
$newstring = "validated"

$files | ForEach-Object {
    $name = $_.FullName.Replace($oldstring,$newstring)
    Rename-Item $_.FullName -NewName $name
}
As you can see, we replaced “testing” with “validated”.