5

I have been using Bulk Rename utility and I have been having some issues. I have some files named things like 664722.pdf,664762.pdf, and 664722-1.pdf that I need to rename. The problem is I have to rename about 50 of these at a time.

So, I am converting from the top to the bottom row.

664722.pdf              664762.pdf              664722-1.pdf
664722-LabelProof.pdf   664762-LabelProof.pdf   664722-1-LabelProof.pdf

So, right now I have to do ([0-9]{6})(-[0-9])? and name the files to \1\2-LabelProof and THEN drop back to ([0-9]{6})(-[0-9])? and name the files to \1-LabelProof I am on windows.

Is anyone able to come up with a Regex that can match both 664722 AND 664722-1 at the same time and I can still call something to convert both jobs with and without subs to have -LabelProof at the end.

I thought about matching something like .pdf to replace it with -LabelProof.pdf, but it wont just be these PDFs. These are just the new ones and I have to leave all of the other ones alone.

nixda
  • 26,823
  • 17
  • 108
  • 156

2 Answers2

3

Use ([0-9]{6}(-[0-9])?)\.pdf and replace with \1-LabelProof.pdf. This will make it so that \1 includes everything before .pdf, on both files with and without dash and a number.

This matches a six numbers in a row, then matches a dash and a number in the form -3 either 0 or 1 times. Basically six numbers and then a - number if it is there.

wingedsubmariner
  • 1,502
  • 7
  • 7
  • No, you understand me wrong. Then I would also be renaming `00258252.pdf` to `00258252-LabelProof.pdf` which would be bad. (this is the standard proof sheet for that cust number.) or in fact would also rename `ShippingDetails1.pdf` or `data_09202013.pdf` or anything that ends in [number].pdf would be renamed. –  Sep 20 '13 at 16:25
  • @user255763 I'm sorry if I didn't understand. What is wrong with your original `([0-9]{6})(-[0-9])?`, what is it matching that it shouldn't, or what is it failing to match? – wingedsubmariner Sep 20 '13 at 16:54
  • on the ones like `665445.pdf` it is matching as `665445\2.pdf` –  Sep 20 '13 at 18:40
  • @user255763 Ah, now I understand. See my updated answer. – wingedsubmariner Sep 20 '13 at 20:30
  • Oh? A sub-pattern? interesting. I didn't know that you can do that. Works perfectly –  Sep 20 '13 at 20:42
  • I added the bad way I had thought of to work right before your answer. yours is still clearly better though, so it's the best answer. I'd upvote, but I can't :( –  Sep 20 '13 at 20:50
1

([0-9,\-]{6,8}).pdf is what I ended up using. It matches a number digit or a - between 6 and 8 times and then the extension to prevent ones that have already been renamed like 665485-LabelProof.pdf from being renamed again and adding a dash. Not the best but it works.

The bad part about this one is that it would also match filenames like --1-45-8.pdf and, without the .pdf at the end like i mentioned, it would also replace

664722-1-LabelProof.pdf
664722-1-LabelProof-LabelProof.pdf