rename files using a text file with paths to them

Discussion in 'Mac Programming' started by smoothisfast, Jul 31, 2010.

  1. smoothisfast macrumors member

    Joined:
    Aug 15, 2007
    #1
    I need some help with this guys.

    I have a text file with a long list of files that i want to rename generated by another program.

    /Users/m/Desktop/Testing/Untitled-1.psd
    /Users/m/Desktop/Testing/Untitled-2.psd
    /Users/m/Desktop/old/Untitled-3.psd

    I want to rename them by adding the word "UpdateThese" to the front of the file name.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    NameChanger might be of help unless you're wanting to do this programatically.
     
  3. smoothisfast thread starter macrumors member

    Joined:
    Aug 15, 2007
    #3
    NameChanger won't parse my text file with the paths to the files I want to rename.
     
  4. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #4
    Wirelessly posted (Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7)

    Should be doable as a bash for loop.

    For each path, rename the file to dirname+/XXX+basename

    http://splike.com/wiki/Bash_Scripting_FAQ#Get_a_file.27s_basename.2C_dirname.2C_extension.2C_etc.3F

    B
     
  5. Peter Maurer macrumors member

    Joined:
    Oct 9, 2008
    #5
    Disclaimer: I'm not sure if it's okay to advertise your own products here. If it isn't, I'd be grateful if a friendly moderator just deleted this post. Moreover, I realize this is the programming board, so an existing product might not be the perfect answer, but with all that said...

    Dragging paths seemed like a useful addition to our little renaming utility, so I just did a quick and (more or less) dirty implementation. Here's how it works: Drag paths from a text file (or copy & paste), then choose your renaming settings as shown in this screenshot ...

    [​IMG]

    ... and finally, click the checkmark button to actually rename your files.

    If that's roughly what you want, smoothisfast, here's the download link.
     
  6. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #6
    Code:
    for file in `cat ~/text.file`; do 
    echo "mv $file ${file%/*}/UpdateThese${file##*/}"; 
    done
    Is basically what I was thinking. (remove the echo " " when done testing).

    I know it could be more "elegant", but this should work. How it handles spaces in filenames will depend on if they are already escaped in the input file.

    B
     
  7. smoothisfast thread starter macrumors member

    Joined:
    Aug 15, 2007
    #7
    that works very well.
     

Share This Page