Skip to content

Quick Powershell tip for avoiding file name collisions when you have images from multiple cameras

My wife and I both have Sony mirrorless cameras. She has an Alpha 5000 and I have a NEX-6. I back up all of our images to my home dev box, and then to a QNAP NAS server. The images are stored in folders based on year and month.

The date based filing makes it somewhat easy to find the images, but when you have images from multiple cameras, you run the slight (but real) risk of having both cameras save an image with the same file name. Both camera use the standard DSCXXXXX naming scheme, where XXXXX is number that is being incremented by the camera.  It’s also a little difficult to quickly separate her images from mine.

So what I do is to use a quick Powershell command to rename my wife’s images. I replace the “DSC” part of the file name with her initials. So lets say that you wanted to replace the “DSC” with “ABC”, a simple way would be with the following command:

Get-ChildItem -Filter “DSC*.*” | 
  Rename-Item -NewName {$_.name -replace ‘DSC’,’ABC’ }

That will get all of the files in the current folder that match dsc.* and pass that list to the rename-item command. The rename-item will iterate through that list and replace all of the occurrences of “DSC” with “ABC”. If you only shoot JPEG files, you can filter on “DSC*.JPG”. We shoot RAW plus JPEG, so we used the wild card extension to get all of the files.

Now can I store her images with mine and they all get backed up to multiple places.  I also back them up to multiple cloud providers, because sometimes it falls down.

If you want to explicitly do just a couple of file extensions, you can use the -Include option instead of -Filter. When you use the -Include option, you must also use the -Path option and set the path. One would be like this.

Get-ChildItem -Path .\\ -Include *.jpg, *.raw | 
  Rename-Item -NewName {$_.name -replace ‘DSC’,’ABC’ }