Script to rename files that have similar names?

Hi, folks.
I have my  RAW files in one folder and my derivative images (e.g., PSDs, TIFFs,  JPEGs) in another.  The derivative files only share the last four digits  of the RAW file names (e.g., the RAW file is named 100826-14278.CR2 but  the JPEG version is only named 4278.JPG).  Also, the derivative files  have no metadata.
Is there a way to use a script to match all the  derivatives to the RAW files based on the last four digits, then change their file names  to match the RAW names.  And, if that's possible, can Bridge then  cascade the metadata minus the camera data EXIF from the RAW files to  the derivative files?
Thanks!
-Greg
P.S. My knowledge of scripting stops with cursive handwriting, so please be gentle.

Thanks the coffee was great!
Here is a new version with subfolder support. Just select the folders as normal and it will search derivitive subfolders.
#target bridge  
if( BridgeTalk.appName == "bridge" ) { 
var newMenuData = new MenuElement( "menu", "Add_Metadata", "after Help", "myMetaData" );
var newDataCommand = new MenuElement( "command", "Rename and Add Metadata", "at the end of myMetaData" , "zxcv" );
newDataCommand.onSelect = function () {
   renamePutXMP();
function renamePutXMP(){
var win = new Window('dialog','Rename and Add Metadata');
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
g.backgroundColor = myBrush;
win.alignChildren="row";
win.g10 = win.add('group');
win.g10.orientation = "row";
win.title = win.g10.add('statictext',undefined,'Rename / Add Metadata');
win.title.helpTip="Compliments of Paul";
win.title.alignment="bottom";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.p1.alignChildren="fill";
win.g5 =win.p1.add('group');
win.g5.spacing=10;
win.g5.st1 = win.g5.add('statictext',undefined,'Raw Files');
win.g5.st1.preferredSize=[100,20];
win.g5.et1 = win.g5.add('edittext');
win.g5.et1.preferredSize=[250,20];
win.g5.et1.enabled=false;
win.g5.bu1 = win.g5.add('button',undefined,'Browse');
win.g10 =win.p1.add('group');
win.g10.spacing=10;
win.g10.st1 = win.g10.add('statictext',undefined,'Derivative Images');
win.g10.st1.preferredSize=[100,20];
win.g10.et1 = win.g10.add('edittext');
win.g10.et1.preferredSize=[250,20];
win.g10.et1.enabled=false;
win.g10.bu1 = win.g10.add('button',undefined,'Browse');
win.g15 =win.p1.add('group');
win.g15.orientation='row';
win.g15.alignment="top";
win.g15.spacing=10;
win.g15.bu1 = win.g15.add('button',undefined,'Process');
win.g15.bu1.preferredSize=[200,30];
win.g15.bu2 = win.g15.add('button',undefined,'Cancel');
win.g15.bu2.preferredSize=[200,30];
win.g5.bu1.onClick=function(){
     rawFolder = Folder.selectDialog("Please select the raw files folder",app.document.presentationPath);
     if(rawFolder !=null){
  win.g5.et1.text =  decodeURI(rawFolder.fsName);
win.g10.bu1.onClick=function(){
     derivativeFolder = Folder.selectDialog("Please select the derivative files folder",app.document.presentationPath);
     if(derivativeFolder !=null){
  win.g10.et1.text =  decodeURI(derivativeFolder.fsName);
win.g15.bu1.onClick=function(){
    if(win.g5.et1.text == ''){
        alert("No Raw folder selected!");
        return;
    if(win.g10.et1.text == ''){
        alert("No Derivative folder selected!");
        return;
    win.close(1);
    process(rawFolder,derivativeFolder);
win.center();
win.show();
function process(rawFolder,derivativeFolder){
var rawFiles = rawFolder.getFiles (/\.(cr2|crw|tif|jpg)$/i);
if(!rawFiles.length){alert("There are no raw files to be processed!"); return;}
var derivativeFiles=derivativeFolder.getFiles (/\.(jpg|tif|psd)$/i);
if(!derivativeFiles.length){alert("There are no derivative files to be processed!"); return;}
var folderList=[];
getFolders(derivativeFolder);
folderList.unshift (derivativeFolder);
derivativeFiles=[];
for (var a in rawFiles){
var Name = decodeURI(rawFiles[a].name).replace(/\.[^\.]+$/, '');
var fileMask = Name.match(/\d\d\d\d$/)+"*.*";
var destFiles=[];
for(var z in folderList){
var destF = folderList[z].getFiles(fileMask);
for(var s in destF){destFiles.push(destF[s])}
for(var z in destFiles){
var Ext = decodeURI(destFiles[z].name).replace(/^.*\./,'');
var destName = decodeURI(destFiles[z].name).replace(/\.[^\.]+$/, '');
destName.substring(4)
   destFiles[z].rename(Name+destName.substring(4)+"."+Ext);
function getFolders(folder) {
    var fileList = folder.getFiles();
     for (var i = 0; i < fileList.length; i++) {
        var file = fileList[i];
if (file instanceof Folder) {
folderList.push(file); 
        getFolders(file);
$.sleep(300);
for (var a in rawFiles){
var Name = decodeURI(rawFiles[a].name).replace(/\.[^\.]+$/, '');
fileMask = Name + "*.*";
var destFiles=[];
for(var z in folderList){
var destF = folderList[z].getFiles(fileMask);
for(var s in destF){destFiles.push(destF[s])}
for(var z in destFiles){
    if(decodeURI(destFiles[z].name).match(/thm$/i)) continue;
updateMetaData(rawFiles[a],destFiles[z])
function updateMetaData(sourceFile,destFile){
if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
sourceFile = new Thumbnail(File(sourceFile));
destFile = new Thumbnail(File(destFile));
var md = sourceFile.synchronousMetadata;
var source = new XMPMeta( md.serialize() );
var md2 = destFile.synchronousMetadata;
var dest = new XMPMeta( md2.serialize() );
try{
copySchema( source, dest,XMPConst.NS_CAMERA_RAW,["RawFileName"]); 
copySchema( source, dest,XMPConst.NS_EXIF,["PixelXDimension","PixelYDimension","ExposureTime","FNumber"]);
copySchema( source, dest,XMPConst.NS_DC,[]);
copySchema( source, dest,XMPConst.NS_XMP_RIGHTS,[]);
copySchema( source, dest,XMPConst.NS_IPTC_CORE,[]);
var updatedPacket = dest.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
destFile.metadata = new Metadata(updatedPacket);
app.document.refresh();
}catch(e){alert(e+" "+e.line);}
function copySchema( source, dest, namespace, omitProps ) { 
var propIter = source.iterator(XMPConst.ITERATOR_JUST_CHILDREN | XMPConst.ITERATOR_JUST_LEAF_NAME, namespace, "" );
var prop = propIter.next();
var prefix = XMPMeta.getNamespacePrefix( namespace );
while(prop) {     
  var name = prop.path.substring( prefix.length );    
   if(omitProps != undefined) var copy = !contains( omitProps, name);
  if( copy ) {
            try{
   XMPUtils.duplicateSubtree( source, dest, namespace, prop.path,namespace, prop.path, 0 );       
            }catch(e){}
  prop = propIter.next();
function contains( arr, member ){
var r = false;
for( var i = 0; i < arr.length &! r; ++i  ) {
  r = arr[i] == member;
return r;

Similar Messages

  • Batch rename files that have non consecutive numbers?

    I have a folder with about 100 image files that have non consecutive numbers. Is there a way to rename them all to add something after the numbers (and before file type extension) without changing the numbers?
    Example: If I select 111019.003.dng and 111019.007.dng, is there a way to batch rename to 111019.003_tk.dng and 111019.007_tk.dng?
    Of course, simply batch renaming w/ a sequence number would change them to 111019.003_tk.dng and 111019.004_tk.dng. Which is no good.
    I realize the easiest way around this is to name them correctly the first time, but I am not the photographer.
    Hope this makes sense, and thanks.

    You can bulk rename in Bridge IE:-

  • The bookmarks listing on my laptop is so narrow I can't distinguish among several bookmarks that have similar names. How do I make the bookmarks large enough to read details on, either on the sidebar or the drop down menu?

    What kind of details do you need? I have a bunch of bookmarks imported from Safari (yes, it's a Mac iBook). In Safari I get a whole page for bookmarks and can see easily which one is which. In Firefox they are stuffed into a narrow space I can't seem to widen and I can't tell a bunch of them apart. The categories are fine because they are one word or two, the specific listings however, are not fine. In one particular category they start the same way, so I have a whole bunch of nearly identical bookmarks and the "abbreviated" listing is not sufficient since it doesn't seem to include the distinguishing features. That's pretty much it. This isn't a problem for all bookmarks, just some. I need to make the window wider so I can see more detail and can't figure out how to do it.
    Thanks, Carol.

    see https://support.mozilla.com/en-US/questions/845800
    Bookmarks Toolbar Fx4 Blue/Folders, Red/Bookmarks - Themes and Skins for Browser - userstyles.org
    /* widen all bookmarks dropdown menus -- Chris Ilias 2007-01-12*/ menu.bookmark-item, menuitem.bookmark-item { max-width: 36em !important; }
    http://userstyles.org/styles/46947/
    try 250px instead of 36em and up or down from there.

  • [SOLVED] rsync updating files that have not changed

    I am trying to setup a backup system for my laptop.  I have a USB hard drive (FAT formatted because I need to backup my wifes Windows laptop too).  However, rsync keeps updating files that have not been touched in anyway between backups.  In fact if I run my backup script twice in a row without otherwise using my computer, some files still get rewritten.
    The rsync command I am using is:
    rsync --force --ignore-errors -rv --delete 
    Any ideas why this is happening.  I removed the options to preserve time, permissions etc because FAT does not support this.
    Edit:  It turns out the advise I read on the internet is wrong and FAT can have time preserved.  This fixed the problem
    Last edited by Allan (2007-08-20 13:34:36)

    I am trying to setup a backup system for my laptop.  I have a USB hard drive (FAT formatted because I need to backup my wifes Windows laptop too).  However, rsync keeps updating files that have not been touched in anyway between backups.  In fact if I run my backup script twice in a row without otherwise using my computer, some files still get rewritten.
    The rsync command I am using is:
    rsync --force --ignore-errors -rv --delete 
    Any ideas why this is happening.  I removed the options to preserve time, permissions etc because FAT does not support this.
    Edit:  It turns out the advise I read on the internet is wrong and FAT can have time preserved.  This fixed the problem
    Last edited by Allan (2007-08-20 13:34:36)

  • I have files that have been on my computer for over a year and all of a sudden they wont open and an error message comes up saying they were improperly downloaded or came in an email attach which is not the case

    I have files that have been on my computer for over a year and I have used them several times and all of a sudden they wont open.  I received an error message saying they are improperly downloaded or came as an email attachement which is not the case.  Please advise

    They seem to be word files - they will open if I choose "open with" microsoft word, but if I double click they don't open they are appearing as PDF on my screen.  I even opened one and then tried to "save as" making sure I chose .doc and they still appear as PDF
    I just created a new document response.doc in word and when I saved to my desktop it appears as a PDF file and I absolutely did not create a PDF or save as PDF it was a simple word
    doc.
    The message says "Adobe reader could not open response.doc because it is either not a supported file type or because the file has been damaged (for example attached in an email and not properly decoded)
    The reader version is I believe the most current, I always update when prompted.  OS is Windows 8

  • I cannot re-open files that have been saved in Numbers version09 - it states "You need a newer version of numbers to open this document". This is the latest version

    I cannot re-open files that have been saved in Numbers version09 - it states "You need a newer version of numbers to open this document". This is the latest version & also the one I have created/saved???

    Jules,
    You may delete Numbers 08 if you wish, but some folks like keeping it around. Close all your Numbers docs and Quit the Numbers app, and the other Numbers app if necessary.Then click the Numbers icon on your doc. Then select Numbers > About Numbers, and in the window that pops up, see which version it is. If the Dock icon started Numbers 08, you can cure that by dragging that icon off the Dock and letting it go in a puff of virtual smoke.
    Now, to put the Numbers 09 icon on the Dock, double-click one of those known Numbers 09 documents so that Numbers 09 starts up. Verify by checkig Numbers > about Numbers.
    Now click and hold the Numbers Dock icon and select the Option for Keep in Dock.
    Jerry
    Message was edited by: Jerrold Green1 -- I inadvertently posted about Pages rather than Numbers. Just corrected it.

  • I have m4v files that have subtitles and sound options they play fine on my computer in itunes and but  when i watch them on my apple tv there is video but no sound ... why ?

    I have m4v files that have subtitles and sound options they play fine on my computer in itunes and but  when i watch them on my apple tv there is video but no sound ... why ? all my other videos are fine and they in mp4 format.

    Mov is a container format, you'd need to look at the codec used by the movie file inside the container to know whether it will work with the Apple TV or not.

  • Import does not recognize old image files that have no extension

    Just discovered that the import facility does not see (or accept) old Mac image files that have no extension -- even if these files have a Mac "kind" that is an image such as "Adobe Photoshop file".
    You can manually add an extension to the file (and respond to an "are you sure?" dialog). Then the file will be seen and accepted.
    This is extremely dangerous (and painful to manually correct) since you think you are seeing all images in the import box, but you are not.
    In fact, I deleted huge image directories after having satisfactorally (I thought) imported them into Aperture many months ago. Most of the old extension-less files had been updated and did have extensions in later versions. However, I missed one important image and looked everywhere for it.
    By a miracle I had a backup of my image directories on a Power Book that I am retiring and finally noticed that the missing image was there just before deleting that directory too! I then figured out why this image (and many others) had not been imported. So, now I am going through manually and adding extensions.
    Does anyone know a better way -- to get Aperture to recognize extension-less images? If not, this needs to fixed in the next version as it is a disaster waiting to happen.
    Tom
    Dual 2.7Ghz G5 ATI Radeon X800 XT 2.5 GB ram   Mac OS X (10.4.6)  

    Well there's an idea...probably would need to go into Bridge <g> to do that most efficiently .. or Automator.
    It turns out that I already had added extension to most (but not all) images in my main image directory and so they got into Aperture alright. I just have to go through all the images in the backup I just found (where many did not get extensions) to find the ones that Aperture missed. So far, there have been just a couple more...
    The real problem is that Aperture should not be missing these, even if they are archaic. At the very least, Aperture's import should give a warning that there are files in a folder that it is not going to import AND is not even showing. Otherwise this is a serious gotcha!
    Tom

  • Is there any easier way to edit imovie files that have been exported as mov file then added to FCE 4?? As every move I make has to be rendered and takes forever??? Also my recording is going out of focus without me touching the camera, why has this happen

    Is there any easier way to edit imovie files that have been exported as mov file then added to FCE 4?? As every move I make has to be rendered and takes forever??? Also my recording is going out of focus without me touching the camera, why has this happened any idea what causes this??
    iMovie '08, Mac OS X (10.5.8), FCE 4

    My daughter has had her Razr for about 9 months now.  About two weeks ago she picked up her phone in the morning on her way to school when she noticed two cracks, both starting at the camera lens. One goes completely to the bottom and the other goes sharply to the side. She has never dropped it and me and my husband went over it with a fine tooth comb. We looked under a magnifying glass and could no find any reason for the glass to crack. Not one ding, scratch or bang. Our daughter really takes good care of her stuff, but we still wanted to make sure before we sent it in for repairs. Well we did and we got a reply from Motorola with a picture of the cracks saying this was customer abuse and that it is not covered under warranty. Even though they did not find any physical damage to back it up. Well I e-mailed them back and told them I did a little research and found pages of people having the same problems. Well I did not hear from them until I received a notice from Fed Ex that they were sending the phone back. NOT FIXED!!! I went to look up why and guess what there is no case open any more for the phone. It has been wiped clean. I put in the RMA # it comes back not found, I put in the ID #, the SN# and all comes back not found. Yet a day earlier all the info was there. I know there is a lot more people like me and all of you, but they just don't want to be bothered so they pay to have it fix, just to have it do it again. Unless they have found the problem and only fixing it on a customer pay only set up. I am furious and will not be recommending this phone to anyone. And to think I was considering this phone for my next up grade! NOT!!!!

  • Why can't the finder in Mountain Lion 10.8.2 find files that have successfully downloaded, or that other programs can find?

    Why can't the finder in Mountain Lion 10.8.2 find files that have successfully downloaded, or that other programs can find?
    This happens with maybe 1 out of 5 files. These are files that have either an ."aa" extention, or or are libraries that icloud can see, but finder can't.

    Files beginning with a period are invisible and library files are system files. Spotlight cannot find either unless configured to do so (btw, this is not a Finder issue but a Spotlight issue.)
    Get Spotlight to search system files (and more)
    Enter the search term in the Finder window's search field.
    Click the [+] button in the search bar to add a search option.
    In the first drop down menu choose Other.
    Choose “System Files” from the list that pops up (and check the box to place in drop down menu to avoid this step later,) click on the OK button.
    Now back in the Finder choose Include from the second drop down menu.

  • How to find PDF files that have other documents bundeled within them?

    Hello guys
    I need help with the following: we have a huge number of PDF files that have other documents imbedded (bundled, attached) in them. If such a document is open in Acrobat, bundled files show up as attachments on the left. Some of those attachements are .mdi files. This is Microsoft Document Images files. Is there a way to flag PDF's that have those .mdi files in them? I need to find them and convert to PDF. If I need to be more descriptive please ask, and thank you in advance for help.

    Preflight is a complex plugin, it's hard to explain how to use it in one forum post. You need to read the documentation carefully.
    There's no pre-built profile for what you want, so you would first create a new Custom Check that compares the MIME type string of embedded files to what you're searching for (not the file extension but the full MIME identifier, which for Office files is a very long string). You would then place that new Custom Check into a new Profile, identifying it as an error condition. Once you've saved the Profile you can run it against a number of files and specify actions to be taken for pass and fail conditions, such as changing the filename or moving to a subfolder.

  • Saving large tiff files we see a lot of times the lines in the saved file that have either missing ( white) pixels or they appear as a black line across entire file or portion of it

    saving large tiff files we see a lot of times the lines in the saved file that have either missing ( white) pixels or they appear as a black line across entire file or portion of it

    Due to the current unavailability of clairvoyants and mind-readers in the forum, we respectfully request you supply sensible, complete details.
    BOILERPLATE TEXT:
    Note that this is boilerplate text.
    If you give complete and detailed information about your setup and the issue at hand,
    such as your platform (Mac or Win),
    exact versions of your OS, of Photoshop (not just "CS6", but something like CS6v.13.0.6) and of Bridge,
    your settings in Photoshop > Preference > Performance
    the type of file you were working on,
    machine specs, such as total installed RAM, scratch file HDs, total available HD space, video card specs, including total VRAM installed,
    what troubleshooting steps you have taken so far,
    what error message(s) you receive,
    if having issues opening raw files also the exact camera make and model that generated them,
    if you're having printing issues, indicate the exact make and model of your printer, paper size, image dimensions in pixels (so many pixels wide by so many pixels high). if going through a RIP, specify that too.
    A screen shot of your settings or of the image could be very helpful too,
    etc.,
    someone may be able to help you (not necessarily this poster, who is not a Windows user).
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • How do I combine files that have already been combined

    How do I combine files that have already been combined?

    Hi Oldshep1959
    I didn't get you ...Please Explain your workflow ...

  • I have a need to open files that have a mq4 and tpl extension. Do you have a program to open these?

    Do you have an add-on or a way to open files that have a MQ4 or TPL extension?

    white_cliff wrote:
    CL90,
    I thought the return policy was 14 days.
    It is ... it changed from 30 days to 14 days in early 2011.

  • HOW DO I FIND FILES THAT HAVE BEEN TRANSFERED FORM MY PC TO MY MAC

    How do i locate files that have been transfered from my PC to my new MacBook Pro

    Depends how they were transferred. If you used Migration Assistant, a new user was created. Look there in your documents folder. If you used Setup Assistant, look in your documents folder.

Maybe you are looking for