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;
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;
I have seen people do some pretty cool things with regular expressions! Any help would be greatly appreciated. Thanks!
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
...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"));
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.
I am hoping to use the regular expression fields in bridge to do the rename.
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); }
};
Copy link to clipboard
Copied
That did exactly what I needed it to! Thank you so much:)
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?
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); }
};
Copy link to clipboard
Copied
This worked. Thank you so much