Changing filenames with Apple Script

Discussion in 'Mac Programming' started by t0ast, Apr 7, 2006.

  1. macrumors member

    Joined:
    Sep 29, 2004
    #1
    I like to keep my replay section for Warcraft III clean, so I was editing loads of filenames when I suddenly realized it could be done so much faster with an Apple Script. Sadly however, I hardly know anything about apple script. I found a sample script made by Apple, but I'm unable to tamper with it to adapt it to my needs.

    Basically, I need the applescript to move segments of a filename.

    I have a great amount of replays named either [xxxxxxxxx]-player1(y)-vs-player2(y).w3g or [xxxxxxxxx]player1(y)-vs-player2(y), where x is the match-ID and y is the players race.

    [wcr20060205]WE_IGE_Sweet_(U)_4K_Grubby_(O)_4.w3g:
    The filename as a whole could be divided into three segments:
    • The match-ID: "[wcr20060205]"
    • Players & races: "WE_IGE_Sweet_(U)_4K_Grubby_(O)_4"
    • extension ".w3g

    What I want the script to do, is to move the ID in the brackets, and the brackets itself behind the players.

    Example:
    [wcr20060205]4K_Grubby_(O)_WE_IGE_Sweet_(U)_5.w3g transfers into
    4k_Grubby_(O)_WE_IGE_Sweet_(U)_5[wcr20060205].w3g

    [Replayers56402]-strifecro(NE)-vs-rara.(HMN).w3g transfers into
    -strifecro(NE)-vs-rara.(HMN)[Replayers56402].w3g


    Thanks in advance, cheers.

    Attachment: Sample script in .txt format from Apple to change filenames, might come in handy.

    EDIT:
    Problem solved, shell scripting ftw
    Code:
    echo "[wcr20060205]4K_Grubby_(O)_WE_IGE_Sweet_(U)_5.w3g" | sed -e "s/\(\[.*\]\)\(.*\)\./\2\1./"
    ---> 4K_Grubby_(O)_WE_IGE_Sweet_(U)_5[wcr20060205].w3g
     

    Attached Files:

  2. macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #2
    look in my homepage for Finder Utility. It is an applescript application that will suit your needs.
     
  3. macrumors 68040

    BakedBeans

    Joined:
    May 6, 2004
    Location:
    What's Your Favorite Posish
    #3
    Not sure if you have Tiger or not but Automator would be easier surely?
     

Share This Page