December 4, 2009 Too Many Files, or How PowerShell Saved me a lot of time.
I originally posted this on my personal blog, but it’s a interesting note so I figured what harm is a little cross posting.
Had a small problem today.
I do a lot of photography and back in 2004 I finally put down the cash for a DSLR and proceeded to shoot whacks of photos. And up until last year everything was good. Then I hit 10,000 photos and the counter on the camera rolled over back to 0001. I didn’t think much of it at the time but the end result was that I started getting duplicate files in the directories that I import my photos into, so there where two files called DSC_0001.NEF on my hard disk.
No problem I figured, I segment the photos into folders based on the year that I shot them so as long as I make sure not to something silly with the photos I should be fine. Now skip ahead a year or so and now I’m seriously considering a copy of Lightroom for managing my photos as it does some really neat stuff with post processing the photos and should really cut down the time I’m spending working on getting photos processed the way that I want.
So, to test I load up a test system with Windows 7, toss in the updates and my applications and then upload a copy of my digital negatives onto the test machine and leave Lightroom to import the entire six years worth of photos. After several hours of grinding away at it I find that there’s a large number of errors during the import – namely that a whole bunch of files are duplicates and already exist in the library. The duplicates that I’ve been shooting for the last year and a bit since the camera rolled over the counter. Turns out that Lightroom doesn’t like to have two files with the same name in the Library, even if they are in different folders.
Rats.
Now I’ve got to find a way to rename all those files without loosing the sequence that they where shot in. Thinking that it’s no big deal I was just going to run the files all back through the program that I use to copy them off the memory cards in the first place, since it’s got the ability to rename files on the fly I thought I could just append the date the photo was taken to the file name and that would give me my unique file names. Unfortunately Nikon Transfer ONLY works with removable media, and I don’t have any media that’s large enough to hold an entire year of photos. That would make the process of importing the files again something that would have to be done 4gb at a time.
There’s 100gb of photos sitting here.
Double Rats.
It’s almost enough to make someone wonder if it’s worth the time just to be able to use Lightroom. Unfortunately it probably is or else I’d just leave it.
So not looking forward to a long process I look through some of the old file rename tricks that I used to do, problem with doing it in dos is that it’s a long script that I really don’t want to write, and I’m not sure that I’ll be trusting a script that I find online with my family photos unless I really know what it’s doing. After a bit of goggling I wondered if PowerShell might be able to assist, and sure enough I found a script that I altered as below:
dir |Rename-Item -NewName {"YEAR-"+$_.Name}
This, when run in the working directory appends a given text string to the name of the file, so all my DSC-0001.NEF files now read 2004-DSC-0001.NEF, and instead of a long and ugly rename process I was able to get everything renamed in a matter of about 5 min. Moving forward I’ll be doing the date append as I import the files from the media cards in the first place.
I think I’ll be picking through PowerShell a bit more to see what it can do, anybody else working with this or using it in conjunction with our products?
- Leave a comment
- Posted under Uncategorized