Automate renaming of files from lists

I have been looking for a utility that cna do this for me, but can't find one.
So I have decided to try and do this via Applescript. But this is getting a bit too complicated for me.
I have about 35,000 files which have to be renamed.
The current file name structure is : AABBBBBBB_CDDD.EEE
"AA_" has to be deleted - *so far so good!*.
The 7 letter code "BBBBBBB" has to be replaced with a new 5 digit product code, but ther rest of the file name ("C_DDD.EEE") must remain the same.
I have an Excell file with the old product code in the first column, and the new product code in the second column.
Anybody out there who can help me?
Many thanks, cos I'm getting seriously bogged down!

*First try this in Script Editor and then try the 'Finder' version [between the (* *) ]*
set changeMidstringInto to text returned of (display dialog "Set BBBBBBB to following 5 digit code..." default answer "")
set theFileName to "AABBBBBBB_CDDD.EEE" -- -REPLACE WITH name of (info for curItem)
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "_"
set myStartString to text item 1 of theFileName
set myStartString to ""
set myMidString to text item -3 of theFileName
set myMidString to changeMidstringInto as string
set myEndString to text items -2 thru -1 of theFileName as string
set theNewFileName to myMidString & myEndString
set theFileName to theNewFileName as string
set AppleScript's text item delimiters to ""
set AppleScript's text item delimiters to ASTID
return theFileName
set changeMidstringInto to text returned of (display dialog "Set BBBBBBB to following 5 digit code..." default answer "")
tell application "Finder"
activate
set frontmost of application "Finder" to true
-- [Optional] select Finder window 1
set curItems to selection -- OR || set curItems to every item in window 1
repeat with curItem in curItems
set theFileName to name of (info for curItem)
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "_"
set myStartString to text item 1 of theFileName
set myStartString to ""
set myMidString to text item -3 of theFileName
set myMidString to changeMidstringInto as string
set myEndString to text items -2 thru -1 of theFileName as string
set theNewFileName to myMidString & myEndString
set theFileName to theNewFileName as string
set AppleScript's text item delimiters to ""
set AppleScript's text item delimiters to ASTID
--return theFileName
end repeat
end tell
*)

Similar Messages

  • Renaming a file from java

    Hello,
    I want to rename a file from a Java Application and I want this operation was very speed.
    I would renaming was "atomic".... not interruptable from Operative System.
    I made this operations in two ways: does anyone explain me if one of these is more efficient than the other one?
    Thank you very much all in advance
    Diego
    First implementation
                            String tmpStateName = stateFname + ".tmp";
                            tmpStateFile = new File(tmpStateName);
                            tmpStateFileStream = new FileOutputStream((tmpStateFile));
                   pd.store(tmpStateFileStream, "System shutdown");
                            tmpStateFile.renameTo(new File(stateFname));
    Second implementation
                            String stateFnameTmp = stateFname + ".tmp";
                   pd.store(new FileOutputStream (stateFname + ".tmp"),
                   "System shutdown");
                            String command = "mv " + stateFnameTmp + " " + stateFname;
                            Runtime.getRuntime().exec(command);
    ....

    But calling exec method of Runtime could I be faster
    than the first implementation??
    I thought that the first implementation was heavier
    (more Java objects created) than the second one...
    Was I wrong?Maybe.
    However it is not relevent. It is just flat out stupid to make things that convoluted in the name of "performance". Especially something like this. All you are really doing in the second implementation is creating a brittle, unmaintable nightmare.
    So don't do that.
    Last but not least I would highly suspect that the first implementation will be faster anyway. You don't seem to be counting on the expense of creating a new process which is not "light" relatively speaking.

  • Hi there, my iMac has automatically been deleting files from my thumb drive when I try to open them.  The lost files aren'tin the trash or anywhere else I can think of.  Any ideas?

    Hi there, my iMac has automatically been deleting files from my thumb drive when I try to open them.  The lost files aren'tin the trash or anywhere else I can think of.  Any ideas?

    If one drive works and the other doesn't that points the finger at the errant drive. They are cheap, replace it. To check formatting right click it in Finder and choose Get Info and look for Format type. Finally do you eject it when removing it or do you just pull it out of the USB connection?

  • Can I set up e-mail to automatically download attached files from a trusted source

    can I set up e-mail to automatically download attached files from a trusted source to a desktop folder?  Can't find the option (if one exists) in "Rules."

    Have you checked Mail > Preferences > General > Downloads folder - change that to desktop. That should do it (that is my setting and it works here).

  • How can i change the settings so that before download the firefox gives a propmt that same file name already exists, instead of automatically renaming duplicate files by adding .1 suffix?

    When I download a file, if a file of similar name already exists in the same download folder, the firefox downloads the file and renames it by adding numeric .1 to the file name.
    I want the firebox to give me a prompt that similar file already exist, rather than automatically renaming it by adding suffix .1.

    Downloads Options
    * https://support.mozilla.com/en-US/kb/Options%20window%20-%20General%20panel#w_downloads
    Unable to Download or Save files
    * https://support.mozilla.com/en-US/kb/Unable%20to%20download%20or%20save%20files
    Check and tell if its working.

  • Using a script to rename a file from the file info cart Cut Num (ID)??

    Hi,
    Can any of you guys tell me if its poss to do a script to rename a wav with the file info, cart, Cut Num ID field....??? (Cart chunks)
    Example file at the moment is called {C5E5F0FE-57D9-4A9A-8DA1-58D1AE7017FD}.wav and I want to grab the info out of the File info, cart section, under Cut Num (ID) which has 9558 in it and rename the file so it is now 9558.wav when it saves or just renames it.I also then want to run the script as i have 6000 plus wav,s to do this too.
    Thanks for any info.
    Glen

    >Can any of you guys tell me if its poss to do a script to rename a wav with the file info, cart, Cut Num ID field....??? (Cart chunks)
    No, scripts in Audition won't let you do this at all. In fact, Audition's scripting function really isn't very file-friendly, relating pretty much just to basic Audition functionality. And there's no way that an Audition script would let you rename a file anyway - they the closest they get to handling any file-related functions is that you can open a designated noise reduction profile - but that's about it.
    There's one place that I know of where you might find a utility to do what you want -
    here (try WidgetPro).

  • RH10: Renaming topic files from FM import

    I have an RH 10 project that is created using FrameMaker as single source (I have the techcomm suite). I want to output in WebHelp format.
    I have another post about getting RH to output the topic files in HTML, however, if no one has a solution to that, I thought I would rename the files in RH.
    However, I have no Rename option, as RH Help says I should. in the Properties dialog box, the name is grayed out.
    Is this because the file names are autogenerated during the Frame Book Import?
    Is there any way to rename files given my project setup?
    Thanks to anyone who can help!
      --Amy

    Thread move to FrameMaker Integration forum.
    I don't think you can freely rename the files for the reason you state. However you can have them created to a formula. It is in the online help and in the topic on my site about Importing and Linking Word documents, it is the same process for this point.
    I am not a FM user so maybe one of those guys can add more.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Batch Renaming Image Files from a list of names

    I would like to use the batch rename function in Bridge CS5 to quickly rename newly uploaded image files of our products.  I would like to rename the image to it's corresponding product number.  The issue is that the product numbers aren't in exact numerical order (ie.  the first pic is of product ES2004 and the next one is for ES2012).  The product numbers can sometimes end with a letter or a number.  The pictures are taken in order of the product numbers on an excel sheet.  What's the easiest way to have bridge name the image file to its corresponding part number? 

    Here is an example script that will do the re-naming also place the original filename into the metadata.
    CSV format is fileName,Product IE:
    p1020337.jpg,E179562
    p1020338.jpg,Z556301
    Copy and paste the script into ExtendScript Toolkit (This gets installed with Photoshop)
    Open Bridge
    Edit > Preferences > Startup Scripts
    Click "Reveal My Startup Script"
    Save the script into this folder.
    Close and restart Bridge and accept the new script.
    To use, navigate to the folder with the documents to rename, "Right mouse click Menu" select "Rename to Product" and select your csv file.
    #target bridge 
    if( BridgeTalk.appName == "bridge" ) { 
    fileNameToProduct = MenuElement.create("command", "Rename to Product", "at the end of Thumbnail");
    fileNameToProduct.onSelect = function () {
       renameToProduct();
    function renameToProduct(){
    var Path =app.document.presentationPath;
    var descFile = File.openDialog("Open Product File","CSV File(*.csv):*.csv;");
    if(descFile == null) return;
    descFile.open('r');
    var datFile=[];
    while(!descFile.eof){
    var line = descFile.readln();
    if(line.length > 5) datFile.push(line);
    descFile.close();
    for(var t in datFile){
    var str=datFile[t];
    str= str.split(',');
    var fileName = File(Path+"/"+ str.shift());
    var product = str.shift();
    if(!fileName.exists) continue;
    var ext = fileName.toString().toLowerCase().match(/[^\.]+$/);
    var thumb  = new Thumbnail(fileName);
    var md = thumb.synchronousMetadata;
    md.namespace = "http://ns.adobe.com/xap/1.0/mm/";
    md.PreservedFileName = thumb.name;
    $.sleep(100); //give it time to update the metadata
    var newName = product + "." +ext;
    fileName.rename(newName);
    alert("All done");

  • Automatically renaming pdf.file

    Hi,
    Does anyone kowns if the following question is possible?
    My scanned documentation gets automatically a file name like for example SKM 217362342 etc. These are PDF.files which I then open with adobe acrobat and then I run OCR.
    After that I want to save them with a name coming automatically from the pdf.file. For instance the invoice number.
    I am not so good in English but I hope you understand my question.
    Thanks in advance

    My problems is I send some PDF files to my own email account from my NB. So this way I can transfer these files w/o using iTunes. But when I was opening my email on iPad, some of the files became PDF files by itself. The reason I want to keep them in PDF is because this way I can organize better on iPad; otherwise it will be all in saved photos. It will be too hard to find the file I need.
    Thank you

  • Automatically renaming pdf files based on excel data

    I am creating pdf certificates using variable data from excel files with InDesign.  This creates a multipage pdf file with a different persons name on each page.  Then end result needs to be individual pdf files named for each person.  I can extract the single pages out of the main pdf ending up with however many files all named the same thing besides a number at the end of the common file name.  Question:  Is there a automated process of renaming the individual files using the data from the excel file?

    You're looking for a PDF Parser or PDF miner tool (PDFminer) as a starting framework, and you'll almost certainly be writing custom code around that as parsing a text file that's effectively free-form and originating from multiple different sources almost always (always?) involves writing customized processing code and an on-going series of tweaks as the suppliers of the PDF change their ticket formats.  (Even apparently-simple details such as the time and date formats, for instance, can vary by geography and language and by supplier, and can derail common processing.)
    In some cases that I can envision, it'd be entirely possible that the data you're after is actually located in an embedded image and not in text that can be parsed.
    The best approach is to get folks to send you JSON or XML or some other format intended for interchange, and avoid the whole mess that is parsing or mining a printer-oriented format.
    The other obvious option is to use something like Amazon's Mechanical Turk or some other explicitly outsourced help.  Depending on how often the formats change and how many of these PDF files you're dealing with and how varied the formats are, sometimes throwing staff at the problem can be the most cost-effective approach.

  • Automatic removal of articles from listing

    Hello,
    We have SAP Retail implemented since 2011.
    Due to the Company's growth strategy we are enhancing and improving the use of Retail functionalities.
    What was customized in a very simple way needs now to be adjusted to support a larger operation.
    Currently there is one General assortment where all materials and sites are assigned to. The listing is created and materials connected to a module are linked to the assortment.
    Some questions regarding implementation and system functionality arised with the need to review customizing and current implementation scenario:
    1 - According to documentation it is possible to have automatic listing procedures. Would it be possible to unlist one material for a specific purpose? For example, if the material is not procured or sold in the past 3 months, we would like it to be automatically removed from the assortment.
    2 - How to prevent CD from 'any' external procurement for a material or a group of materials?
    In this case there still may be the scenario where stores have to return improper goods to CD. Stores are considered as Vendors in this case, so is our CD. I need to be able to differentiate the CD trying to procure externally from stores returning improper goods to the CD.
    3 - Where can I find documentation about the tables flows and relationships during the listing , articles deactivation, assortment changes, articles removed from assortments...and so on. I would like to have the big picture about Retail tables during major materials changes.
    4 - Is there a Best Practice document for using SAP Retail apart from SAP Help?
    I appreciate your attention and any assistance you can provide.
    Best Regards,
    Claudia

    Hi Uma,
    I don't think there is any such program available in SAP as if user is expired then anyway system will not allow him to login and if user is valid then there is no need of performing this action separately as by logic it is same as role removal and should be handled as per standard logic.
    Hope this helps.
    BR,
    Mangesh

  • HT1473 How do you rename files on a playlist within iTunes? Trying to rename some files from audio CD.  Thanks

    How do you rename files on a playlist in iTunes? Don't see a rename function and want to rename files coming in from audio CD as "track one."  Thanks

    Right-click the track, choose Get Info, and go to the Info tab.  Overtype the Name (and/or any other information that you want to change) with the new information.  Click OK when you are done.

  • How to rename  doc file from powerbuilder

    Hi,
    What is the method to rename the  testfile.doc  into  testnewfile.doc from powerbuilder. Please  can u give an idea it would be appreciate.
    Regards
    Pol

    Hi Polachan;
      In PowerScript, You could also use the FileCopy & FileDelete combination or the FIleMove (old,new) & FileDelete as well. On a more primitive level you could use the FileReadEx, FileWriteEx, FileDelete commands. Just remember to only delete the original if the new file creation is OK.
      Other alternatives:
    1) Shell out of your PB application and run the DOS Rename command
    2) Call the MS-Windows API - rename, _wrename
    HTH
    Regards ... Chris

  • Find multiple files from list

    Hello everyone,
    I have googled and searched this forum for a solution to my problem and have had no luck. What I need to do is find a list of files all at once. I'm a photographer and my situation is that I will do a photo shoot and have 5k images that I submit to a photo editor. They will choose about 80-100 selects that I then need to process. The problem is that I can find no way to take the editors list of selects and just select those images and move those to a new folder without going through the list and copying each files one by one. Is there a search string I am missing (I tried, filename, filename and filename; filename but no luck) or a app anyone knows that could allow me to do this? Locating each file one by one is a time sink!
    Many thanks for any help.

    Well, I figured out a way to do it using a text editing program and the Terminal. You need a text program that will allow you to find and replace carriage returns with spaces (I use TexEdit Plus), then you use the mv command in Terminal. Thus, I had a list:
    adamshot.tiff
    adam-display.jspa.png
    adam-me.jpg
    badgeadam.icns
    flicon.jpg
    Replacing the carriage returns with a space I got this:
    adamshot.tiff adam-display.jspa.png adam-me.jpg badgeadam.icns flicon.jpg
    I created a new folder in the folder containing the images and called it "Moved" and then launched Terminal. I changed directory so that I was "in" the parent folder--just type cd and a space, then drag the parent folder into the Terminal and drop it. The command will look something like this:
    Tiger:~ francine$ cd /Users/francine/Pictures/Travelin/1994/
    Hit the return key. Now do the move command by typing mv followed by a space, then copy and paste the single line of the files list followed by a space, and then the name of the folder:
    mv adamshot.tiff adam-display.jspa.png adam-me.jpg badgeadam.icns flicon.jpg Moved
    Hit return again and everything in the list will be in the Moved folder. If this all seems way beyond what you want to try you might post your query in the Automator forum and see if anyone has an easier solution.
    Francine
    Francine
    Schwieder

  • Automatic upload of file from a directory

    Hi All,
    We have huge nunber of files and we are planning to upload this data to cubes but we want to avoid the manual process and make it automatic.
    I know that we can write the code in infopackage to pick the file based on system date but is ther any code which can help me to pick file one after another without actually giving any name or path for file in the infopackage.
    Regards
    Rahul

    No. It is a lot of code and quite complex and you have to modify for your purpose anyway.
    This can only be used as a startup guide.
    Here is the schema:
    First manualy create a template infopackage
    Repeat next in a loop for every file(you have to control how many loads run in parallel).
    1) use this to create copies of the InfoPackage:  
      CALL FUNCTION 'BAPI_IPAK_CREATE_FROM_REF'
        EXPORTING
          INFOPACKAGE_REF     = TemplateInfoPack
          TEXT                = InfoPackName
       IMPORTING
         INFOPACKAGE          = InfoPackage
         RETURN               = s_Return.
    2) Create the data objects and read the template infopackage parameters:
        CALL FUNCTION 'BAPI_IPAK_GETDETAIL'
         EXPORTING
           INFOPACKAGE         = TemplateInfoPack
         IMPORTING
           DETAILS             = s_Details
           SCHEDULING_PARAMS   = s_SchedulingParams
           DESTINATIONS        = s_Destinations
           FILE_PARAMS         = s_FileParams
          TABLES
            SELECTIONS         = t_Selections
            INFOCUBES          = t_Infocubes
            THIRD_PARTY_PARAMS = t_Third_Party_Params
            RETURN             = t_Return.
    3) Change the generated package. Acually only change file name
      s_FileParams-FILENAME = YourNextFileName.
      s_Details-TEXT = InfoPackName.
      free t_Return.
      clear t_Return.
      CALL FUNCTION 'BAPI_IPAK_CHANGE'
        EXPORTING
          INFOPACKAGE              = InfoPackage
          DETAILS                  = s_Details
          SCHEDULING_PARAMS        = s_SchedulingParams
          DESTINATIONS             = s_Destinations
          FILE_PARAMS              = s_FileParams
        TABLES
          SELECTIONS               = t_Selections
          INFOCUBES                = t_Infocubes
          THIRD_PARTY_PARAMS       = t_Third_Party_Params
          RETURN                   = t_Return.
    4) Start the load:
      CALL FUNCTION 'BAPI_IPAK_START'
        EXPORTING
          INFOPACKAGE = InfoPackage
        IMPORTING
          REQUESTID = ReqID
        TABLES
          RETURN = t_ReturnExe.
    5) Check(periodically in a loop) the request status:
          CALL FUNCTION 'BAPI_ISREQUEST_GETSTATUS'
            EXPORTING
              REQUESTID        = w_ReqID
           IMPORTING
             TECHSTATUS       = w_TECHSTATUS
             TECHINFO         = w_TECHINFO
             QUALSTATUS       = w_QUALSTATUS
             QUALINFO         = w_QUALINFO
             LOCATION         = w_LOCATION
             RETURN           = w_RETURN.

Maybe you are looking for

  • Memory/Speed early 2009 IMac

    I have an IMac (20 inch early 2009) With 2 GB 1067 MHz DDR3 memory and after updating to Yosemite 10.10.1  it has slowed down. I was wondering if increasing the memory would help speed things up?

  • I have a new iMac - how do file share my music and photos from my old mac to my new mac?

    I want to transfer my music and photos from one Mac to another - but I don't want to transfer anything else - what is the best way to do this? Thanks

  • Images with success and error messages

    Hi, I am using theme 20. I want to add a success image on all success messages and an error image on all validation failure messages. I can do this by putting img tag in messages individually. Is there an easy way by which I can make sure that all su

  • Cannot Open Nikon D90 Raw files in Photoshop Elements 7

    Does anyone have advice on how to get Photoshop Elements 7 to read Nikon D90 Camera Raw (.NEF) images? When I try to open one of these Raw images, I get an error message saying that the program does not recognize that file type.

  • ADF examples !

    Hello ! im a newbie desperate looking for ADF examples please help