I have a folder containing files generated by screen captures. The files are named ImageN.jpg and imageNN.jpg, where N is of course a digit. I want to rename all the ImageN.jpg files to Image0N.jpg and leave the ImageNN.jpg files alone. I have tried and tried to do this with no success. However I structure the regexes, I either get no rename or I get all the files renamed. Here are examples.
If someone could please tell me what I'm doing wrong I would greatly appreciate it. It's probably something simple, but I just can't see it. Thank you.
Edited to add: I've looked again at your first example and it's not quite the same as mine, you need to escape the "." before "jpg" or it is interpreted as "any character" by the regex engine. So the regex to identify the files you want is ::image(\d)\.jpg
Thank you for your response, Roger, but I tried that and it simply doesn't work for me. Please see the following capture. TCC says that a rename occurred, but it didn't. It just renamed the file to the same name it had previously, without the added 0.
As you can see, I am running version 27.00.23, which I believe is the latest version.
There's a case sensitivity problem now Jesse, sorry that's my fault, I wasn't paying close enough attention to your original post. The regular expression is case sensitive, so try
Code:
rename ::Image(\d)\.jpg ::Image0\1.jpg
It's odd though that the lower case version seems to be matching some files (which it shouldn't) and then not renaming them (which is correct as they don't match the regex)
OMG. I feel like an idiot. How embarrassing. Yes, of course, regexes are case-sensitive. Sigh.
But in my defense, I can only plead that I didn't notice this because, as you wrote, "It's odd though that the lower case version seems to be matching some files (which it shouldn't) and then not renaming them."
Thank you for your help, Roger. It is very much appreciated.
"\d" means a single digit. You could try "\d+" (one or more digits) but you might wind up with files renamed more than once and even if not, 1-digit numbers, 2-digit numbers (...) will all get a single '0' prepended.
It's too bad you can't put "\1" inside a variable function; then you could compute the number of 0s (using @len[\1]) needed and use @repeat in the new name.
Thanks for your reply, Vince, but the \d wasn't the issue. The problem was case-sensitivity. However, there appears to be a bug in that the first regex is matching both "Image" and "image" yet the rename isn't occurring.
You are correct, BTW, that when I used \d+ all digits were prepended with 0. That certainly wasn't what I wanted.
See RogerB's post above time stamped 5:10 yesterday for the key to the solution to my problem.
Getting a little more complicated, this will also work (and will maintain capitalization of the filename):
Code:
[H:\]ren /n ::(?i)(image)(\d)(\.jpg) ::\{1}0\2\3
H:\Image1.jpg -> H:\Image01.jpg
H:\image2.jpg -> H:\image02.jpg
2 files would be renamed
But, as @RogerB said, it's odd that when ignore-case is not specified:
Code:
[H:\]ren /n ::image(\d)\.jpg ::image0\1\.jpg
H:\Image1.jpg -> H:\Image1.jpg
TCC: (Sys) Cannot create a file when that file already exists.
"H:\Image1.jpg"
H:\image2.jpg -> H:\image02.jpg
1 file would be renamed
The find portion of the rename matched both files; since case insensitivity was not specified, it should not have matched Image1.jpg.
The replace portion of the first rename skipped the character in the replacement string following "image".
In fact, the replace portion skips even more, and simply uses the original filename:
Code:
[H:\]ren /n ::image(\d)(\.jpg) ::foogexyz\1\2
H:\Image1.jpg -> H:\Image1.jpg
TCC: (Sys) Cannot create a file when that file already exists.
"H:\Image1.jpg"
H:\image2.jpg -> H:\foogexyz2.jpg
1 file would be renamed
You can put almost anything you want on the right side, as long as it starts with "::" and contains a regex construct, and you'll get the same result. Sometimes, e.g., in this example (bad replacement regex), both renames trigger the weird error:
Code:
[H:\]ren /n ::image(\d)\.jpg ::x\3\4fiiet
H:\Image1.jpg -> H:\Image1.jpg
TCC: (Sys) Cannot create a file when that file already exists.
"H:\Image1.jpg"
Invalid back-ref
H:\image2.jpg -> H:\image2.jpg
TCC: (Sys) Cannot create a file when that file already exists.
"H:\image2.jpg"
0 files would be renamed
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.