I like logic, and I know how to say in English (and perhaps in formal logic) how I want a command to perform, but I don't know regular expressions per se.
Thread 84 helped me get about 98% of where I want to go, but I need to get that last two percent. Here's my conundrum:
I got a camera in late December 2006. Pentax Optio W20. Great camera. Versatile and portable. Waterproof. I highly recommend it. If I can get this renaming thing to work, I might even buy a W60 to reward Pentax for making such a great little gadget.
The problem is, like most consumer-grade cameras, it names images IMGP0001.JPG to IMGP9999.JPG, and after that rolls over to IMGP0001.JPG again. The camera's solution is to put it into a different folder, which is completely useless since I toss my photos around my hard drive six folders from Sunday.
So now I've only 300 or so photos left until it turns over. I don't want multiple files of the same filename on my hard disk--that's just asking for trouble.
So I can either buy another camera (from a different manufacturer that uses a different naming scheme, probably only buying myself another 10K-1 photos), or find a way to alter the naming scheme and not spend money unnecessarily on a new camera.
If I had left all my photos in their original filenames, I would be set:
- Code: Select all
Replace: ^(IMGP)([0-9]{4})
With: \10\2
The problem is, I've renamed many of the files. Renaming "IMGP1021.JPG" to "Billy's hot sister.jpg" isn't a problem, but I've lately found it useful to retain the original filename and also rename the file, so I'd rename "IMGP6745.JPG" to "IMGP6745 - Billy's not so bad himself.JPG".
With the above formula, this extra information gets stripped off.
I was thinking about the following, but it re-applies the algorithm to files that have already been renamed, making them six and more digits long. I want a reuseable formula:
- Code: Select all
Replace: ^(IMGP)([0-9]{4})(.*)
With: \10\2\3
I'm pretty sure that any file I've renamed would NOT have a number immediately following the four digits following IMGP, so I think I'd be looking for a formula that does the following (in English, not regexp):
It's possible that I'm unable to do this, which is why I'm asking you regexp'erts instead of driving myself madder stabbing in the dark.Look for a file which:
1 - May or may not have text before the following expression
2 - Has the characters "IMGP"
3 - Has four digits immediately following the "IMGP"
4 - May or may not have a character that is NOT a digit following those four
5 - May or may not have additional characters after that non-digit character
And do this with it:
1 - Retain the text from step 1 earlier
2 - Retain the text from step 2 earlier
Put the digit 0 in here [1 after I've rolled over]
3 - Put those four digits back here after the 0
4 - Retain the text from step 4 earlier
5 - Retain the text from step 5 earlier
I suppose that I could also replace instances of IMGP with IMGO and it would still sort right for the next ten thousand photos, but that's just so... inelegant.
I also suppose I didn't need near as much detail as I put in here.
Much appreciated if you can help.
- RG>