Windows comes with a program called Powershell. This program, being at the same time the place (a shell) and the scripting language for executing automated actions, should be useable for renaming a series of images in one go by creating a loop which will rename any file found corresponding to the parameters previsouly set up.
For the following explanation we will assume that we have a series of tiff images (with the .tif extension), that are located inside a folder called ‘tunnel’. And we want to renumber these images tunnel_0001.tif, tunnel_0002.tif, tunnel_0003.tif and so on.
Process
- open Powershell, a console with a blue background appears;
- in Powershell, next to the PS line, go to the folder where the images are located using the
cd
(change directory) command:cd C:\*path*\tunnel
;1 - once inside the folder (from Powershell’s console point of view) execute the following command:
$i = 1 ; Get-ChildItem *.tif | ForEach-Object{Rename-Item $_ -NewName ('tunnel_{0:0000}.tif' -f $i++)}
- eventually, we can execute the
dir
(directory) command to list what is inside the folder and then check if the files have been renamed.
Explanation
What matters in this process is this line: $i = 1 ; Get-ChildItem *.tif | ForEach-Object{Rename-Item $_ -NewName ('tunnel_{0:0000}.tif' -f $i++)}
. I will explain the bits that need to be understood in order to be able to customize them when having to use the action for a different scenario:
$i = 1
: we set a variable ($
) called ‘i
‘ to which we give a value of1
. This is the number from which we want our sequence to start. It means that we can put something like 54 instead of 1 if we want our sequential numbers to start by 54;Get-ChildItem *.tif
: it tells Powershell to select all files (*
), within this folder, which have a tiff type of file extension (.tif
). So if we are working with jpg, for example, we should put*.jpg
;- if we want a name before the number, which will be the same for every file, we have to add it before the extension inside the brakets of the
-NewName
command. In this example the common name istunnel_
, which then can be replaced by whatever we want; {0:0000}
: this is where we get our padded zeros. On the left of the colon is our padding, if we change its value we will obtain a FormatError; the padding can only be 0, we can’t have something like tunnel_***1.tif, tunnel_*256.tif, for example. On the right of the colon is the number of placeholders that form our sequential number. In this example, four zeros means that every number having less than four placeholders will have the gap filled up with zeros: tunnel_0001.tif, tunnel_0002.tif […] tunnel_2395.tif;23$i++
: it tells the program to add one to the number of each new file renumered. Without it, it would simply renumber every files with the value of$i
(here it is 1), which in the practical sense means we would have just one file as our OS won’t accept two files with the same name.
The End