Skip to main content
New Participant
April 20, 2015
Answered

I need help renaming a file using regular expressions in Bridge.

  • April 20, 2015
  • 1 reply
  • 1276 views

Hi,

I work at a university, and we are working through files for our Thesis and Dissertations. We have been renaming them to make them more consistent. I am just wondering if there is a regular expression that could help with this process?

Here is come examples of current file names;

  • THESIS 1981 H343G
  • Thesis 1981 g996e
  • THESIS-1981-A543G

I don't need to change the actual names of the files. just how they are formatted.

Proper case on Thesis.

Hyphens(-) in all white space.

First letter capital, last letter lowercase on the call no (H343g)

So the list above should look like;

  • Thesis-1981-H343g
  • Thesis-1981-G996e
  • Thesis-1981-A543g

I have seen people do some pretty cool things with regular expressions! Any help would be greatly appreciated. Thanks!

This topic has been closed for replies.
Correct answer I have gone

You would be better off using a script to do this as an example as I don't think it would be possible in the Bridge re-name.

Using ExtendScript Toolkit or a Plain text editor copy the code into either and save it out as Filename.jsx

This needs to be saved into the correct folder. this is found by going to the preferences in Bridge, selecting Startup Scripts, this will open the folder where the script is to be saved.

Once this is done close and re-start Bridge.

To Use: Goto the Tools Menu and select Rename PDFs

Make sure you test the code with a few copied files into a seperate folder first to make sure it does what you want.

The script will do all PDF files in the selected folder.

#target bridge 

if( BridgeTalk.appName == "bridge" ) { 

renamePDFs = MenuElement.create("command", "Rename PDFs", "at the end of Tools");

}

renamePDFs.onSelect = function () {

app.document.deselectAll();

var thumbs = app.document.getSelection("pdf");

for( var z in thumbs){

var Name = decodeURI(thumbs.spec.name);

var parts = Name.toLowerCase().replace(/\s/g,'-').match(/(.*)(-)(.*)(-)(.*)(\.pdf)/);

var NewName = parts[1].replace(/^[a-z]/, function(s){ return s.toUpperCase() });

NewName += parts[2]+parts[3]+parts[4]+parts[5].toUpperCase().replace(/[A-Z]$/, function(s){ return s.toLowerCase() });

NewName += parts[6];

thumbs.spec.rename(NewName);

    }

};

1 reply

New Participant
April 22, 2015

Hi Philip,

Thanks for submitting an answer. It is a little over my head:-/

The list I gave is just a few of several thousand files. all will be in a very similar format

(Thesis) (year) (four-five digit call_no that begins and ends with a letter)
(Thesis 1988 M129e)
The first part needs to be proper case (Thesis vs THESIS or thesis)
The spaces need to have hyphens between them.
The first letter of the call_no string always needs to be capital, and the last letter needs to be lowercase.

I am hoping to use the regular expression fields in bridge to do the rename.

New Participant
April 24, 2015

You would be better off using a script to do this as an example as I don't think it would be possible in the Bridge re-name.

Using ExtendScript Toolkit or a Plain text editor copy the code into either and save it out as Filename.jsx

This needs to be saved into the correct folder. this is found by going to the preferences in Bridge, selecting Startup Scripts, this will open the folder where the script is to be saved.

Once this is done close and re-start Bridge.

To Use: Goto the Tools Menu and select Rename PDFs

Make sure you test the code with a few copied files into a seperate folder first to make sure it does what you want.

The script will do all PDF files in the selected folder.

#target bridge 

if( BridgeTalk.appName == "bridge" ) { 

renamePDFs = MenuElement.create("command", "Rename PDFs", "at the end of Tools");

}

renamePDFs.onSelect = function () {

app.document.deselectAll();

var thumbs = app.document.getSelection("pdf");

for( var z in thumbs){

var Name = decodeURI(thumbs.spec.name);

var parts = Name.toLowerCase().replace(/\s/g,'-').match(/(.*)(-)(.*)(-)(.*)(\.pdf)/);

var NewName = parts[1].replace(/^[a-z]/, function(s){ return s.toUpperCase() });

NewName += parts[2]+parts[3]+parts[4]+parts[5].toUpperCase().replace(/[A-Z]$/, function(s){ return s.toLowerCase() });

NewName += parts[6];

thumbs.spec.rename(NewName);

    }

};


Wait, One thing I just noticed... I am sorry I didn't point this out.

Some of the files are Thesis-1979D-C198s

Is there a way to modify that script to keep the optional letter immediately following the numbers a capital?