Batch file renaming, Automator?

Discussion in 'Mac Programming' started by LordMelkor, Aug 6, 2008.

  1. LordMelkor macrumors newbie

    Joined:
    Aug 6, 2008
    #1
    Often times I download files where the spaces are replaced by underscores, so I made a workflow in automator that replaces all the _'s with spaces. But in addition to the _'s, files often have tags which I wish to remove, such as the crc32 within brackets. However, the Automator replacement, doesnt seem to allow any wildcard type replacements (ie. remove all stuff within brackets). How can I implement this into my Automator workflow (like could I add a bash or applescript component after the text replacement to do this?)

    Thanks!

    P.S. And I'm looking specifically at an automator workflow solution, because of the convenience of being able to run it from the right-click menu.


    Example:
    Original Filename -
    [blah]_abcde_fghi_[11CB25F].txt

    Want -
    abcde fghi.txt
     
  2. tedsmith3rd macrumors member

    Joined:
    Aug 30, 2006
    Location:
    US
    #2
    Might want to give this a look: Regex File Renamer 0.1

    Then you could use a regular expression like \[.+?\] and replace it with nothing.
     
  3. LordMelkor thread starter macrumors newbie

    Joined:
    Aug 6, 2008
    #3
    Thanks! That works. But what would I have to include to include to remove the preceding and trailing _'s (sorry I'm not familiar with perl syntax :eek:)
     
  4. tedsmith3rd macrumors member

    Joined:
    Aug 30, 2006
    Location:
    US
    #4
    Try just adding another regex file renamer to your workflow after the one above and have it change "_" to a space.
     
  5. LordMelkor thread starter macrumors newbie

    Joined:
    Aug 6, 2008
    #5
    If I do that, ill have a leading and trailing Space instead of a leading and trailing _ either way, if that's the case I cant sort the files properly by name since the first letter is preceded by a space.
     
  6. tedsmith3rd macrumors member

    Joined:
    Aug 30, 2006
    Location:
    US
    #6
    Try adding another with ^\s*(.+?)\s*$ to $1 (or \\1)
    If that doesn't do it then try these instead: ^\s* to blank and \s*$ to blank

    Still no joy? Start over and change _ to space first, then change \s*\[.+?\]\s* to blank.
     
  7. LordMelkor thread starter macrumors newbie

    Joined:
    Aug 6, 2008
    #7
    This doesn't seem to do anything... :confused:

    So close but not quite :( it removes everything correctly but I lose the spaces in the file name itself!!

    i.e.
    Input: [WOWEE]_saywot_wazzup_[butterblarg].txt
    Output: saywotwazzup.txt
    Desired: saywot wazzup.txt
     

Share This Page