• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Apr 20, 2015 Apr 20, 2015

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

915

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Apr 22, 2015 Apr 22, 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

...

Votes

Translate

Translate
Enthusiast ,
Apr 22, 2015 Apr 22, 2015

Copy link to clipboard

Copied

This should give you a start.

var Names =  ["THESIS 1981 H343G","Thesis 1981 g996e","THESIS-1981-A543G"];

var Names2=[];

for(var a in Names){

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

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() });

Names2.push(NewName);

}

alert(Names2.join("\n"));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2015 Apr 22, 2015

Copy link to clipboard

Copied

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.

Capture.PNG

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 22, 2015 Apr 22, 2015

Copy link to clipboard

Copied

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);

    }

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 24, 2015 Apr 24, 2015

Copy link to clipboard

Copied

That did exactly what I needed it to! Thank you so much:)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 24, 2015 Apr 24, 2015

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 24, 2015 Apr 24, 2015

Copy link to clipboard

Copied

This should fix that problem.

#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].toUpperCase()+parts[4]+parts[5].toUpperCase().replace(/[A-Z]$/, function(s){ return s.toLowerCase() });

NewName += parts[6];

thumbs.spec.rename(NewName);

    }

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 24, 2015 Apr 24, 2015

Copy link to clipboard

Copied

LATEST

This worked. Thank you so much

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines