Simple batch renamer for Windows 10 PowerShell

I’m currently sitting in front of one of our Windows 10 computers that does not have Cygwin or Git BASH installed so there’s no way for me to quickly rename TIFF files from command-line like I am used to . . . enter Windows PowerShell!

I need to rename the files according to the formula <filename_stub>_<###>.tif such that a file like SMDR_1950s-SF-37_May-17-2017_12-51-19.tif becomes SMDR_1950s-37_001.tif. In this case, the <filename_stub> is SMDR_1950s-37 and <###> is 001.

So I wrote a little Windows PowerShell script to help out.

# filename: rename_tifs.ps1
 # PowerShell script to rename multiple TIFFs within a folder to a name that increments by 1

# ask user for input
 $filename_stub = Read-Host "What is the new filename stub? i.e. 'CRLA_1995' without underscore or index number"

# $variable.ToString("000") will convert an integer into a string that is zero-padded to 3-spaces
 Dir *.tif | ForEach-Object -begin { $count=1 } -process { rename-item $_ -NewName ($filename_stub + '_' + $count.ToString("000") + '.tif'); $count++ }

I like using Notepad++ to edit scripts in Windows but regardless of your preferred text editor, copy and paste the above into a file and save it as rename_tifs.ps1.

Copy & paste or move rename_tifs.ps1 into a folder of TIFFs you need to rename, right-click it, then select Run with PowerShell. It will pop-up a window asking for the filename_stub to use then rename the files for you before closing the window.

Many of the digital techs use Adobe Bridge to rename on Windows 10 if we’re not using the command-line, but it is a resource hog! Going forward, I can see us using this little utility on Windows for simple tasks.

Jeremy Moore