Copy link to clipboard
Copied
Hi
I know I've done this in the past but cannot seem to work it out today.
I have a series of images "_####_[layercompName].png". I would like to remove the underscores and numbers. The underscores removal is easy, but how do I remove the numbers (####) when they are different for each filename? I would like the end result to be [layercompName].png
The reason I have these filenames in the first place is that I have run the photoshop script "layer comps to files", and this adds a number sequence prefix. I have tried to alter the script following various instructions I've found from trawling the internet (this one included How do you remove the number sequence when exporting layer comps to files? CS6. Windows 8.) but without any luck. So now I'm resorting to batch renaming in Bridge.
Thanks!
3 Correct answers
If you are referring to the “code” that is typed in once the “use regular expression” checkbox has been ticked:
Regular expression - Wikipedia, the free encyclopedia
Also known as GREP or RegEx for short.
As long as the pattern of your existing filenames is consistent, these should work.
To remove the last _ and the characters after it
To change _+ to -
Click the Preview button to confirm everything is correct, including the file extention, before you run it. Also, select the "Preserve current filename in XMP" option so you can revert back in case there is a problem.
@yuri5 – I like the answer from @gregreser – however, here is another equivalent method for the regular expression find and replace using capture groups:
Find:
(^.+?\+)(.+)(-)(.+)(_\+)(.{2})(.+)(\.[^\.]+$)
Or perhaps "better", Find:
(^.+?\+)(.+)(-)(.+)(_\+)(.+)(_.+)(\.[^\.]+$)
Replace with:
$2_$4-$6$8
Copy link to clipboard
Copied
but how do I remove the numbers (####) when they are different for each filename? I would like the end result to be .png
Try Batch Rename String substitution.
Assuming your only numbers used are in the sequence number you could try to add a criteria for each number using the plus sign. So 1 for 0, another for 1, then 2, etc etc. Leave the replacement empty and if you add the underscore to the list it should be possible to do so in one go.
But for security first back up the files before messing around with it because same filenames overwrite each other often!.
Copy link to clipboard
Copied
Here you go, taken straight from: DesignEasy: How to Remove Sequence Numbers and Empty Spaces When Exporting Layers and Layer Comps
- Run Adobe Bridge and navigate to the folder with exported files.
- Select all files which have sequence numbers.
- Go to Tools > Batch Rename.
- Choose: String Substitution from the first drop-down list in New Filenamessection. From the second drop-down choose: Original Filename. In the Find: text field type: _\d{4}_ (underscore, backslash, letter d, open bracket, number four, closed bracket, underscore). Leave Replace with: text field blank. Ensure that you have Replace All and Use Regular Expression checked as shown on the screenshot below.
- Click on the Preview button in the top right corner and ensure that files will be renamed as you want.
- Click on Rename button and you are done.
In case you are first time doing this and you still have doubts if everything will work as expected, check Copy to other folder option when renaming files. This option is located near the top left corner under: Destination Folder.
Another thing I want to mention is to remove everything that you have below String Substitution options. In case you see additional renaming options just click on minus (-) sign on the right side to remove them.
How to remove/substitute empty spaces in the file name using Adobe Bridge
It is pretty similar process. The only difference is that you should type: \s (backslash followed with letter s) in the Find: text field. You can leave Replace with: text field blank or to type underscore.
Copy link to clipboard
Copied
Thank you very much! This is what i looked for Could i ask you for one more thing? What do those numbers mean? Is it some kind of script language? Thanks
Copy link to clipboard
Copied
If you are referring to the “code” that is typed in once the “use regular expression” checkbox has been ticked:
Regular expression - Wikipedia, the free encyclopedia
Also known as GREP or RegEx for short.
Copy link to clipboard
Copied
Thank you Steve, that's interesting and i haven't heard about that since now. I am definitely going to go thrue.
Copy link to clipboard
Copied
Karffe, there are many sources of information on RegEx on the internet, web pages, interactive tutorials, videos etc. You could start by searching the Adobe Bridge and InDesign forums for the terms Regular Expression/RegEx (Bridge) and GREP (InDesign) for specific uses.
A general internet search for the same keywords will kick up a whole lot more. A great interactive tutorial/tester can be found here:
Copy link to clipboard
Copied
I love this information! I've got a client who always adds a random string of letters and numbers to the end of files but then wants them removed. They always end in _e8 or another set of letter/number. I've tried this code but my guess is it's not working since there are letters? Do you have a suggestion for altering this code to work for this circumstance? Thanks for your help!
Copy link to clipboard
Copied
"\d{2}" means two digits (0-9) but a different sequence would not be found. You have to figure out what is common to all of your files, then write a pattern to match. For example, do you always want the last three characters deleted? Is there always an underscore? Etc.
Copy link to clipboard
Copied
@andrewsartistry – As @Lumigraphics wrote, the search pattern that you used does not match your text pattern.
There are many equivalent regex patterns that could be used for your example. Some options include:
Find:
(.+)(_.{2})(\.[^\.]+$)
Replace:
$1$3
or
Find:
_.{2}
Replace:
or
Find:
_\w\d
Replace:
Copy link to clipboard
Copied
I cannot thank you enough virtuaxe. Not only for your solution, but for taking the time to share your knowledge.
Copy link to clipboard
Copied
Hello all! virtuaxe do you mind seeing if you can help me with my own issue with this problem?
Before knowing about RegEx + string substitution, I didn't think I'd be able to solve an issue of removing sequence numbers. I've created a thread with my issue here: Sequential reordering error fix?
Basically, I have files exported from Lightroom with sequence numbers appended to the front of the filenames. They used to represent the order of images in a book layout I was doing. When things moved around... I didn't know how to rename all the files at once given they already had sequence numbers in the filenames, and changing even just one file would disrupt everything. I hope that makes sense.
Unfortunately this method doesn't work for me- I've attached a screengrab of my bridge window here. I'm thinking this issue is stemming from the fact that bridge cannot find the original filename in my files, given they were exported from Lightroom and not PS as layer comps.
Copy link to clipboard
Copied
Your files have 3 leading digits, however the regex that you were using was looking for a fixed value of 4 digits. It also appears that you may have mistakenly added a space and an underscore at the beginning. So, if you add a caret ^ at the start and remove the leading space, leading underscore and change {4} to {3} it should work on all 3 digit strings.
The following code does not care how many number of digits, just as long as the filename starts with 1 or more digits and ends in an _ underscore (offers greater flexibility than hard coding in a specific number of fixed digits).
There are at least two valid approaches (notice the syntax highlighting to help understand what is going on):
Find: ^\d+_
Replace:
(blank, nothing)
Find: (^\d+_)(.+)
Replace: $2
P.S. It is usually a wise move to tick the box “Preserve current filename in XMP metadata” so that it is easy to undo the batch rename if something goes wrong (also use the preview button on the upper right to preview all files, rather than just the single file preview at the foot of the interface).
Copy link to clipboard
Copied
I have read all the posts, however, there use to be a way to manipulate the actual PSD code in the LIB.Html file so you can easily do an export to files and the sequence numbers would not apply. You would need to do it everytime PSD Updated. Does anyone have that information? I can't find my original code file.
Copy link to clipboard
Copied
Hi Stephen,
Though I am chiming in here 1,127 days late and a dollar short, I am experiencing a problem similar to those of the previous posts. Due to a lack of knowledge in coding, I could not use the solutions you provided to solve my problem so am writing to you with the hopes you will catch this.
I too have a sequence of numbers and letters I want to remove from my filenames, of which there are hundreds. I understand the basics of how to do a batch rename but my aforementioned lack of coding seems to be tying me up.
Basically, the existing filenames that are in the following format:
A2R1037VA3258_0000000a_20200923_232324.mp4
A2R1037VA3258_0000000b_20200924_000528.mp4
A2R1037VA3258_0000002a_20200924_023056.mp4
A2R1037VA3258_0000002f_20200924_024453.mp4
A2R1037VA3258_0000003a_20200924_030551.mp4
Similar to a previous post, there is a sequence of numbers which changes. The sequence beings with a series of zeros and ends with a number and lowercase letter. I want to remove the number/letter sequences before the "DATE_TIME", resulting in the files being named:
20200923_232324.mp4
20200924_000528.mp4
20200924_023056.mp4
20200924_024453.mp4
20200924_030551.mp4
...and so on.
I was so close to finding the solution...help me, Stephen Marsh-Kenobi. You're my only hope!
Copy link to clipboard
Copied
You can search for everything before the second underscore and delete that.
Copy link to clipboard
Copied
Yes but the problem is that the numbers after the first underscore are all different, so how are they searched for and removed/changed without going one by one?
Copy link to clipboard
Copied
That's what regular expressions are for.
Copy link to clipboard
Copied
Hi everyone I had searched a lot but can't find solution to this problem.
The final name should be this "A16228_0IAJH_100-50"
what do I need to add? I'm going crazy
Copy link to clipboard
Copied
For one file, just rename it. For MULTIPLE files, you HAVE TO find a pattern. What is the pattern that matches the other files you want to rename?
Copy link to clipboard
Copied
Thank for the response, a list like that
P-CROWN-Q1+A16070-0HAYT_9XX_+50_1.png
T-ADJUST-Q9+A16066-0GRAI_9XX_+51_2.png
F-SLIMMY-IND+A16228-0IAJH_100_+50_1.png
should become something like this
A16070_0HAYT_9XX_+50.png
A16066_0GRAI_9XX-51.png
A16228_0IAJH_100-50.png
Copy link to clipboard
Copied
sorry like this
A16070_0HAYT_9XX+50.png
A16066_0GRAI_9XX-51.png
A16228_0IAJH_100-50.png
Copy link to clipboard
Copied
i mean this
A16070_0HAYT_9XX-50.png
A16066_0GRAI_9XX-51.png
A16228_0IAJH_100-50.png
Copy link to clipboard
Copied
As long as the pattern of your existing filenames is consistent, these should work.
To remove the last _ and the characters after it
To change _+ to -
Click the Preview button to confirm everything is correct, including the file extention, before you run it. Also, select the "Preserve current filename in XMP" option so you can revert back in case there is a problem.
Copy link to clipboard
Copied
@yuri5 – I like the answer from @gregreser – however, here is another equivalent method for the regular expression find and replace using capture groups:
Find:
(^.+?\+)(.+)(-)(.+)(_\+)(.{2})(.+)(\.[^\.]+$)
Or perhaps "better", Find:
(^.+?\+)(.+)(-)(.+)(_\+)(.+)(_.+)(\.[^\.]+$)
Replace with:
$2_$4-$6$8


-
- 1
- 2