Batch Duplicate File > Then rename?

Discussion in 'Mac Apps and Mac App Store' started by eclipse525, Sep 7, 2012.

  1. eclipse525 macrumors 6502a

    eclipse525

    Joined:
    Aug 5, 2003
    Location:
    USA, New York
    #1
    I have a situation where I need to take a file and then duplicate the file several times renaming each new file by adding a length to the end of each one. Below is an example of what I am trying to accomplish. Is this something that would be appropriate for "Automator"? If so, how can I accomplish this task? Thank you for any help!*

    Example:

    Original file name: *BOC-CABLE.jpg

    Need to create these variants:

    *BOC-CABLE03.jpg
    *BOC-CABLE06.jpg
    *BOC-CABLE15.jpg
    *BOC-CABLE25.jpg
    *BOC-CABLE50.jpg
    *BOC-CABLE75.jpg
    *BOC-CABLE100.jpg


    PS-> I''ve got the renaming thing down with an application called "A Better Finder Rename" but the tricky part is a duplicating the file and then renaming it to add the new part name.


    Thank you!
    ~ErickP
     
  2. GGJstudios macrumors Westmere

    GGJstudios

    Joined:
    May 16, 2008
    #2
    I think you may need to create the duplicates first, then rename them. To duplicate them, just copy the file and paste repeatedly in Finder. For renaming large numbers of files/folders, I use Name Mangler and I've heard good things about NameChanger.
     
  3. eclipse525 thread starter macrumors 6502a

    eclipse525

    Joined:
    Aug 5, 2003
    Location:
    USA, New York
    #3
    Yeah, I was afraid of that. I currently use "A Better Finder Rename" to rename files but it's the duplicating part that is tricky. I have SO many files I need to do this too that it's a scary thought. I'll keep looking in hopes that there is a solution. Thank you!


    ~erick
     
  4. GGJstudios macrumors Westmere

    GGJstudios

    Joined:
    May 16, 2008
    #4
    I don't know how many files you have, but duplicating is a very fast process. Just select the file(s) you want to duplicate in Finder, then press Command-C to copy. Then, while holding the Command key down, press the V repeatedly, for as many copies as you want.
     
  5. robgendreau macrumors 68030

    Joined:
    Jul 13, 2008
    #5
    I think the following would help in Terminal:

    for num in {001..10}; do cp file file.$num; done

    It would get you filename1.jpg, filename2.jpg, etc. So at least the duplication would be done; I don't know how you'd get the numbers you want since I don't know how they're generated.
     
  6. aalegado macrumors newbie

    aalegado

    Joined:
    Aug 24, 2001
    Location:
    Lost Wages, Nevaduh
    #6
    Put this in a shell script:

    Code:
    #!/bin/sh
    string=$1
    stringlength=${#string}
    startpos=$[stringlength-4]
    lastchar=$[stringlength-4]
    basename=${string:0:$lastchar}
    extension=${string:$startpos:4}
    cp "$string" "$basename"03"$extension"
    cp "$string" "$basename"06"$extension"
    cp "$string" "$basename"15"$extension"
    cp "$string" "$basename"25"$extension"
    cp "$string" "$basename"50"$extension"
    cp "$string" "$basename"75"$extension"
    cp "$string" "$basename"100"$extension"
    
    When you execute it, supply the filename of the file that you wish to duplicate. If the filename is *BOC-CABLE.jpg then in the Terminal you would enter:

    Code:
    ./scriptname.sh *BOC-CABLE.jpg
    
    The script will take the filename you input, and copy it each time putting a literal value between the basename and the extension. You can see in the script where the literal value is. This is brute-force code but it's easily extended: Just duplicate the

    Code:
    cp "$string" "$basename"XX"$extension"
    
    line and replace XX with the value.

    Since the values are hard-coded in the script but you enter a filename each time, you can use this script against all the files that you have to copy/rename as long as they all need to have the same range of values.

    You could make this more elegant by putting the values in an array and then looping through the array and doing the cp operations using an indexed variable but...my brain can't handle that right now. :)
     

Share This Page