Rename files in reverse order

Hi all,
I'm looking for a script that can rename "n" files inside a folder in reverse order (preserving extension):
OLD NAME --> NEWNAME
file1.ext --> file(n).ext
file2.ext --> file(n-1).ext
file3.ext --> file (n-2).ext
file(n) --> file 1
Is there something available online to do that with Apple Script? I've tried almost al "renamer tools" available but none can do such a thing and I'm not able to script something so this is why I'm asking here
TIA

The following script should do what you are asking for, although it is rather slow with folders containing a large number of files. There most likely exist much faster solutions. I hope this one can help anyway. Run the script from the AppleScript Editor.
*set theFolder to choose folder*
*tell application "Finder"*
*   set theFiles to files of theFolder as alias list*
*   set N to (count theFiles)*
*   set N2 to 2* * *N + 1*
*   repeat with thisFile in theFiles*
*      set {theName, theExtension} to {name, name extension} of thisFile*
*      set {theName, theNumber} to my rename(theName, theExtension)*
*      set name of thisFile to theName & (N2 - theNumber) & "." & theExtension*
*   end repeat*
*   set theFiles to files of theFolder as alias list*
*   repeat with thisFile in theFiles*
*      set {theName, theExtension} to {name, name extension} of thisFile*
*      set {theName, theNumber} to my rename(theName, theExtension)*
*      set name of thisFile to theName & (theNumber - N) & "." & theExtension*
*   end repeat*
*   set theFolderName to name of theFolder*
*end tell*
*tell me to activate*
*beep 2*
*display dialog "The " & N & " files of folder “" & theFolderName & "” have been renamed in reverse order." buttons {"OK"} default button 1 with icon 1*
*on rename(theName, theExtension)*
*   set L1 to (offset of "." & theExtension in theName) - 1*
*   set theName to text 1 through L1 of theName*
*   set theDigits to {}*
*   repeat with k from 1 to L1*
*      set thisDigit to item -k of theName*
*      if thisDigit is in "1234567890" then*
*         copy thisDigit to the end of theDigits*
      else
*         exit repeat*
*      end if*
*   end repeat*
*   set theNumber to (reverse of theDigits) as text*
*   set L2 to length of theNumber*
*   if L1 = L2 then*
*      set theName to ""*
   else
*      set theName to text 1 through (L1 - L2) of theName*
*   end if*
*   return {theName, theNumber}*
*end rename*

Similar Messages

  • How can i bulk rename music files in reverse order from artist - song name to songname - artist

    How can I bulk rename music files in reverse order from artist - song name to songname - artist.
    I actually dont need to rename the actual files.
    Its just i have a huge txt list of 100,000 music names that are listed as so..
    Artist - Song Name
    Artist - Song Name
    Artist - Song Name
    Artist - Song Name
    Artist - Song Name
    Artist - Song Name
    and i need this list to reverse it self so it is listed in the list as
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Im sure there is some kinda way to auto a mix of applescript/automator/terminal to do something like:  all char before the "-" replace with the chars after the "-".
    Please some one help me if you know how I can pull this off

    How can I bulk rename music files in reverse order from artist - song name to songname - artist.
    I actually dont need to rename the actual files.
    Its just i have a huge txt list of 100,000 music names that are listed as so.
    I wonder if we haven't misunderstood what you were asking for. Could it be that you have not a huge file, but just a huge list of names in many small files. If that's the case, you should rather use the following script instead of the previous one.
    Since this script does not rename the files, make a backup of your files before running it.
    set theFolder to choose folder -- the folder containing your text files
    tell application "Finder"
        set theNames to name of files of theFolder whose name extension is "txt"
    end tell
    set theTextFiles to {}
    set theFolderPath to POSIX path of theFolder
    repeat with thisName in theNames
        copy theFolderPath & thisName to the end of theTextFiles
    end repeat
    repeat with thisFile in theTextFiles
        set F1 to open for access thisFile
        set theText to read F1
        close access F1
        set theParagraphs to paragraphs of theText
        set bigList to (a reference to theParagraphs)
        set theNewParagraphs to {}
        set bigNewList to (a reference to theNewParagraphs)
        repeat with X in bigList
            set P to offset of " - " in X
            if P = 0 then
                set Y to X
            else
                set Y to text (P + 3) through -1 of X & " - " & text 1 through (P - 1) of X
            end if
            copy Y & return to the end of bigNewList
        end repeat
        set theNewText to text 1 through -2 of (bigNewList as text)
        set F2 to open for access thisFile with write permission
        set eof F2 to 0
        write theNewText to F2
        close access F2
    end repeat
    display dialog "Done!" buttons {"OK"} default button 1 with icon 1
    Message was edited by: Pierre L.

  • Renaming files in sequential order

    Automator experts, please help. I am stumped. I manually export photos from iPhoto. When they are exported, the file names are created in the order that they appear in the album. Here's the iss
    1. In the Finder, I've got my images listed in order (image1.jpg, image2.jpg, etc...)
    2. I select all of the images, and I click the "rename images" plug-in that I created. All it does is take the selected finder items and renames them. I have the action pop up when it is executed.
    3. I change the filename to rename sequentially, and I change the filename. For example, the format is: 2006-spring-1.jpg (where "1" is the sequential digit)
    4. Well, it renames the files, but messes up the order! image1.jpg should be 2006-spring-1.jpg and image2.jpg should be 2006-spring-2.jpg and so on, but this doesn't happen. image1.jpg may be 2006-spring-6.jpg and so on.
    So it does the job, but changes the order. Any idea why this happens? Would creating an Applescript be better? (Not that I know how to do that...)
    MacBook Pro 17", iMac G4 800MHz, 60GB iPod (5th Gen)   Mac OS X (10.4.7)  

    Try this AppleScript:
    tell application "Finder"
    set my_folder to folder "untitled folder"
    repeat with this_item in (get items of my_folder)
    set the_name to name of this_item
    set name of this_item to "2006-spring-" & items 6 thru (count the_name) of the_name
    end repeat
    end tell
    The folder's name goes between the quote marks in line 2; different folders in the path can be specified by using : between each element of the path.
    (16443)

  • Reading file in reverse order i.e. end to begining

    Hi all
    How i can read file starting from end toward start. any utility method. all ideas are welcome.
    Thanks you all
    MK

    Hi
    Thanks for good info
    ya ! I got many files with different sizes..
    Actual file structures is like..
    Record1.......900.characters.......................
    2..................900......................
    .// record number varies for all files
    second last...900 characters....
    last...........900 characters.......
    some time file strucure may be...
    Record1.......900.characters.......................
    2.......................all the rest of the record is one line ..
    I need last two to read (1800 characters)... It is not guaranted that each records will in each line. In some files they may scattered in different lines(that is why i am using Random Acess Files)
    but i got one thing good..I can pick things from last two records as token as these two records contains fix name token, which i want.
    as app. require efficiency, so my problem is to read ony last 1800 characters..
    Thanks a lot for your kind interst
    mk

  • How can I bulk sort by capture time and  bulk rename files off multiple cameras?

    I have found many renaming utilities, including bridge, but I have not run across any that allows bulk / batch capture time sort and rename?
    I can sort by capture time in Lightroom 3, but when I export it puts the files back in original order....maybe I am doing something wrong....that would not surprise me. 
    I just tried sorting by Capture Time in LR3 and then exporting and renaming.... renamed but not in the capture time sort order....    
    so I am open to any suggestions... I shoot 2 cameras 99% of the time so I do not need to change lenses.
    Thanx in advance.

    How can I bulk rename music files in reverse order from artist - song name to songname - artist.
    I actually dont need to rename the actual files.
    Its just i have a huge txt list of 100,000 music names that are listed as so.
    I wonder if we haven't misunderstood what you were asking for. Could it be that you have not a huge file, but just a huge list of names in many small files. If that's the case, you should rather use the following script instead of the previous one.
    Since this script does not rename the files, make a backup of your files before running it.
    set theFolder to choose folder -- the folder containing your text files
    tell application "Finder"
        set theNames to name of files of theFolder whose name extension is "txt"
    end tell
    set theTextFiles to {}
    set theFolderPath to POSIX path of theFolder
    repeat with thisName in theNames
        copy theFolderPath & thisName to the end of theTextFiles
    end repeat
    repeat with thisFile in theTextFiles
        set F1 to open for access thisFile
        set theText to read F1
        close access F1
        set theParagraphs to paragraphs of theText
        set bigList to (a reference to theParagraphs)
        set theNewParagraphs to {}
        set bigNewList to (a reference to theNewParagraphs)
        repeat with X in bigList
            set P to offset of " - " in X
            if P = 0 then
                set Y to X
            else
                set Y to text (P + 3) through -1 of X & " - " & text 1 through (P - 1) of X
            end if
            copy Y & return to the end of bigNewList
        end repeat
        set theNewText to text 1 through -2 of (bigNewList as text)
        set F2 to open for access thisFile with write permission
        set eof F2 to 0
        write theNewText to F2
        close access F2
    end repeat
    display dialog "Done!" buttons {"OK"} default button 1 with icon 1
    Message was edited by: Pierre L.

  • Sort list reverse order

    I want to sort a list of files in reverse order e.g.  oldest to newest instead of newest to oldest I seems the ony options are date, name etc.

    Right click (Control click) on the column headings and make sure you have the right 'Date' term select that you want to sort.
    Then click on the column heading ('Date Modified' in the case below) to change from oldest to newest and newest to oldest. The triangle will flip upside down as you do so.

  • Reverse order in File- Open dialogue

    The file/folder list in the File->Open dialogue window is "stuck" at showing in reverse order. I can right-click in the Open dialogue window and sort ascending, but the next time I open a file it is back to reverse order.
    I have experimented with Explorer's view settings but Reader appears to ignore those. Other applications, for example Word, use Explorer's view settings and behave as I would expect.
    I suspect that someone has inadvertently changed something on this PC. Perhaps there's a keystroke combination that changes the file display order persistently?
    Any ideas, please?
    Adobe Reader version 8.1.2
    XP Pro SP2

    I'm still struggling with this - does anyone know how to change the file sort order in the File->Open dialogue?
    It must be possible to change it because it has somehow been changed to reverse order!

  • PDF files print in reverse order per page

    Hi - I am trying to figure out if this is an adobe issue or a printing issue.  It is happening only on this user who is on Adobe 9.1 -everyone else is on 7.0 and they aren't having this issue.  So maybe it  is  a combo.
    When the user prints a PDF which was a powerpoint file (she did not creat it was sent via email) she selects 2 per page and hten selects doublesided - landscape and collates staples top left hand side.
    File prints doublesided and collates, but what would be slide one would be on the bottom of the page and what would be slide 2 would show at the top.  On the back of the 1st page  slide 3 is at the the bottom and slide 4 is at the top.  Staples at the bottom right.
    Printer settings seem ok......there is a selection for order and top to bottom is selected.  Reverse order is NOT selected.
    Are there any settings in Adobe that would cause this?  I have googled and though there are some similar questions no one has answered.
    specs:
    Windows XP Professional SP3
    Adobe 9.1 (latest updates)
    Canon IR C5185 (multifunction color)
    thanks in advance. Robin

    Hey,
    Please let me know what is your Reader version.
    Open Reader and go to Edit->Preferences->Accessibility and deselect 'Replace Document Colors' option.
    If this does not help, then try repairing Adobe Reader and then check.
    Let me know.
    Regards,
    Anubha

  • Why does InDesign always open multiple files in reverse number order?

    Whenever I select multiple InDesign files to open, despite being named accordingly Page_01, Page_02, Page_03, etc. InDesign always opens them in reverse order tabs. If I open 10 spreads at once instead of staring at page 1 I'm looking at the back.
    Is there any way to fix this? It's driving me mad. I cannot think of why it would be doing this.

    Create a book (File -> New -> Book...) and add your files to it. Rearrange the files to the order you want. Then select the needed files and double-click to open them. The tabs will be populated respecting the order the files appear in the book.
    Important: BEFORE adding the files to the newly-created book, go to the book panel menu, choose "Book Page Numbering Options..." and deactivate "Automatically Update Page & Section Numbers", to avoid unwanted renumbering of your pages.

  • When I try to insert several pdf files into an initial one, they consistently are attached in reverse order, no matter how I instruct the program. How do I correct this?

    I am working with Acrobat X Pro. I open a pdf, then try to insert several files, in a specific order, into the first one. No matter whether I instruct it to place the files after the first, last or name a page number, the files are inserted in reverse order after the initial file. How do I overcome this problem?

    Thanks Bill !! for providing the simple answer - this has saved me much work.  I always assumed that Acrobat would either a) sort the inserted files alphanumerically or b) use the sort order of the OS's file selector.  The c) answer of inserting the files in the reverse order of the OS file selector (since Acrobat will reverse that order) eluded me until now.  
    It's clearly a bug in the program, I'm using Acrobat X Pro, but had the exact same problem with Acrobat 7 - never occurred to me to sort the file listing in reverse alphanumeric order in order to have Acrobat insert them in correct alphanumeric order.
    Thank!

  • Reading file line by line in reverse order

    hi,
    can anybody tell me that how can I read a txt or csv file line by line in reverse order?
    thanks in advance.

    Please don't cross post - http://forum.java.sun.com/thread.jspa?threadID=5283758&messageID=10193925#10193925

  • Unable to use reverse geocoding when renaming files

    I've asked about this on different discussion boards but no answer so far. The first versions of Lightroom that came with reverse geocoding did not have this problem. But somehow after an update in Lightroom 4 the Google reverse geocoded location fields cannot be used to rename files. This was very convenient for me to export images to people as a landscape photographer working in many places and making it easy for others to locate the place via the filename.
    Is this a bug or a Google rights thing? And is there a way to make reverse geocoded metadata permanent (not in gray and italics?) because when I overtype the place myself it does work.
    Example below: note that the fields {Country} and {City} or not added to the file name, even though they are in the metadata field.

    Don't use realtive paths, at least not without making them absolute yourself.
    Java gives you the ability to figure out the path from which the executing program was loaded. Use that, together with your relative path, to construct an absolute path.

  • How to copy images from another MC in reversed order??

    Hi everyone,
    I'm new to AS3 and have been fighting and searching for a solution to this problem for a week now, and I'm VERY close!
    I crated a MC holding of a series of images (about 50) and I jump around in it using plenty AS3 scripts (most of which I don't fully understand yet, but I'm working on that to! )
    I had to find a way to "rewind" (= play backwards) the MC. Since there is a stop(); command in almost every frame, prevFrame does not work and if I put that in a loop, it goes WAY to fast (but worked).. So I could think of only one way...
    Create a new (reverserd) MC with the same image sequence ald reverse it manually and play that one.
    This all works fine (very proud of it ).
    Now my question:
    To get this to work for multiple image sequences, I have to load all images twice (once in MC_1 and again in MC_2 and select them and reverse them).
    Not a big one, unless you want to create MANY of those SWF's...
    Is it possible to load the 50 images of the first MC in reverse into the second MC dynamically? JUST the images, noting else.
    extra info: the MC_2 is already in the lib(empty) and placed on the stage.
    something like:
    var pointer:Number=1;
    for (var:i:Number=50;i>=0;i--) {
    get MC_1.picure(var);
    put it in MC_2.frame(pointer);
    pointer = pointer + 1;
    All help is welcome and please take into account that I have little experience and copy most of my scripting from people like you
    T.I.A.
    Melluw

    I tried your advice (thanks for that)
    The event I already have is the mouse leave
    I //-d out the part I removed (what did work)
    The code I ended up with is:
    function Start() {
    stage.addEventListener(Event.MOUSE_LEAVE, cursorHide);
    function cursorHide(evt:Event):void {
    var currFrame = MC_1.currentFrame;
    if (CCW == true) {  //it is true in this case
      movStart = (50 - currFrame);
    else {
      movStart = currFrame;
    if (movStart>25) {
      MC_1.prevFrame();
    // removed swapChildren(MC_1, MC_2); // This is the part I removed
    // removed MC_2.gotoAndPlay(movStart);
    else {
      MC_1.gotoAndPlay (movStart);
    And if I leave the stage on the part where movStart is indeed >25
    Nothing happens,
    So I guess this is not what you meant
    Subject: Action Script 3 how to copy images from another MC in reversed order??
    I cannot direct you in the loading of the images approach, it will be too complicated, and will probably not work anyways... when you move away from a frame that has dynamic content, you lose the content.  So basically, there is nothing practical in taking that approach.
    I do niot understand what the problem will be with the enterFrame/prevFrame approach. If everything you can do with the mouse is already used (which I doubt) by the first mc, then there is nothing else you can do with this file.  You probably just need to rethink your control scheme.  You should search Google for "AS3 slideshow tutorial", and to lighten up your design, add "XML" in that search.
    >

  • Deleting & renaming files - is there a shortcut to finder?

    I am a recent convert from PC to Mac. So far so good. However, one thing starts to drive me up the wall which is deleting/renaming files in programs such as photoshop, word, excel etc.etc.
    As far as I can tell, this is only possible in the finder menu. Is this Correct? I am using a lot of folders and subfolders - sometimes 3-4 levels deep. Every time I need to change/delete a file or filename - lets say while in photoshop, I have to go to finder and click my way through several levels of folders to the actual file I need to change. This is somewhat annoying and timeconsuming.
    Question 1: is there a way to do these operations in - lets say photoshop directly?
    Question 2: If not, is there a shortcut key that would point me automatically to the file in finder where I can make the changes?
    Your input would be very helpful and save me some aggravation.
    fupe

    Hi Greg,
    Thanks for your input. You are correct as far as "save" and "save as" is concerned. Windows and Mac work the same way.
    However, as far as I can tell, in Mac you can only "delete" or "rename" a file in "finder" which forces you to open up finder and locate the file in order to delete or change it.
    In windows you can do these 2 functions directly in the program (such as photoshop, excel or words). You do not have to go to "explorer or root directory" to make these changes which I believe would be the equivalent of "finder".
    In any case, Terence solved the problem. By command clicking the name (title) of the file in any program, it opens up the directory in "finder". This way makes it easy to select the file and do the changes.
    fupe

  • Automator: Impossible to rename file using automator under Mac OS X Lion

    Hi,
    Before upgrade my iMac to MAC OS X Lion 10.7.2, I had service created with automator under snow leopard in order to rename my pictures file names by blocks instead of one by one. Since I'm using Lion, this one doesn't work anymore. I have completely recreate the service under Lion and the results is the same.
    You can find below my workflow that is easy. The problem is the message error in the history of automator application. The message is "impossible to rename file "file name" because this one should create conflict with existing file". I already test a lot of times with different name where I'm sure that this one doesn't exist on my Mac but all the time without success (verify also with search function under mac)
    If somebody can help me, it would be very interesting because I already tried to find answer on internet without success too.
    Thanks in advance for your help.

    the whole automator and in particular the record action was substantially rewritten in snow leopard. and the record action is slow, unreliable and you can't trouble-shoot it. it's a wonder it works at all. the only advice i can give is to use it as little as possible. if at all possible avoid it altogether. if you do need to use it try using keyboard strokes instead of the mouse movement. for example. use command+c and command+v for copying and pasting and use tabbing to choose the correct box on the page.

Maybe you are looking for

  • How can I stop Firefox from remembering a password for a site, so anyone on a shared computer can't use it?

    Someone who used our home computer must have clicked "Do you want Firefox to remember this password?" when using one of my shopping sites. So now when I try to sign in to that site, the password and email are already filled in, and I just have to cli

  • ASMLIB for RHELAS3.0

    Does the continued absence of ASMLIB for RHEL AS 3.0 mean that automatic storage management is unavailable for this platform? I have found very little mention of anyone using ASM on linux. Does the installation of Oracle on the ext3 file system remai

  • Checkbox submit problem.

    Hi, Im working on adf faces with jdev 10.1.3 . There is a checkbox which shud render a button based on its value. If i use onclick="submit()" it works correctly, but I dont want it to submit the page fully. Is there some other way to do it . I tried

  • Main Sub not displayed correctly on the FPL9

    Hello Experts, We have requirement to credit the GL account only after payment is received against the specific receivable e.g. $ 20 charge posted on the account and $ 18 payment clears the charge partially then crediting the GL account for $ 18. In

  • VAT and CST details for Company Code

    Hi All I have a requirement to store following details at the company code and plant level in SAP ECC for India implementation. Can someone please guide me where can I store these information in SAP ECC 6. VAT - Plant Level CST - Plant Level TIN - Co