Mac rename files using a text file with paths to them

smoothisfast

macrumors member
Original poster
Aug 15, 2007
38
2
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.
 

balamw

Moderator
Staff member
Aug 16, 2005
19,366
978
New England
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
 

Peter Maurer

macrumors member
Oct 9, 2008
69
21
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 ...



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

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

balamw

Moderator
Staff member
Aug 16, 2005
19,366
978
New England
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
 

smoothisfast

macrumors member
Original poster
Aug 15, 2007
38
2
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 ...



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

If that's roughly what you want, smoothisfast, here's the download link: Name Mangler 2.2.2 Beta
that works very well.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.