Rename and Number Pictures with PowerShell

by Christian Fredh 9. November 2009 04:46

I had a problem. I had all these pictures taken from my recent journeys. When copying them over to my computer, they all had obscure file names like IMG_343.NEF. They were in raw format (.NEF) so the otherwise nice Windows feature of importing pictures didn’t recognize them, and the camera program didn’t have a fast way renaming them.

So, I thought: Let’s try to solve it with PowerShell, felt that I needed to play around with PowerShell anyway. Thought I share the script I used. It could definitely be used with other files as well, but I think pictures is the most common files to apply it to.

Please, be aware that I’m not a PowerShell expert, I’m not responsible of what happens to your files, and take backup of your files before using it.


Get-ChildItem | Sort-Object CreationTime | %{$suffixNumber=1} { %{$suffixString="{0:D3}" -f $suffixNumber} 
{ Rename-Item $_ -NewName "Las Vegas $suffixString.nef" ; $suffixNumber++ } }

The Get-ChildItem cmdlet gets all files in the folder you are in, and then we are piping the results to Sort-Object which sorts the files by creation date, and then for each file, we are renaming it and then increasing the number we are adding to the file name. I read the article Renaming Files by Jeffrey Snover to help me with this.

Change the $suffixNumber=1 if you want it to start from 0 or some other number. The $suffixString="{0:D3}" -f $suffixNumber is formatting the number to include leading zeros if nessesary. You can change the number 3 if you want more or less leading zeros. I read the article Windows PowerShell Tip of the Week - Formatting Numbers to help me with this. And, of course, change "Las Vegas " to what ever makes sense to your case.

The result was files with nice looking file names, Las Vegas 001.nef, Las Vegas 002.nef, Las Vegas 003.nef and so on.


Tags: , ,



11/9/2009 5:17:44 AM #


Pingback from

Twitter Trackbacks for
        Christian Fredh | Rename and Number Pictures with PowerShell
        on |

11/9/2009 3:12:17 PM #


Social comments and analytics for this post

This post was mentioned on Twitter by christianfredh: New blog post - Rename and Number Pictures with #PowerShell -

uberVU - social comments |

Comments are closed

Powered by BlogEngine.NET
Theme by Mads Kristensen

About Christian Fredh

Christian Fredh

A twenty six year old solutions architect and developer living in Stockholm, Sweden. I work as a SharePoint consultant at Avega Group with .NET and SharePoint development.


The opinions expressed herein are my own personal opinions and do not represent my employer's view. Use the information on this site at your own risk.


Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.

© Copyright 2009, Christian Fredh.