daemon
daemon

Reputation: 372

Trim 4 chars from filename (1000+ files)

I have 1000+ images with filenames like this "300_03e05a1f5fb83bc113edaa898b2c46f3.jpg" and I need to get rid of first 4 characters (300_) of each filename. I could not find any tool for Mac that can do that and I dont know appropriate terminal command. Can anyone help me?

Thanks

Upvotes: 1

Views: 1834

Answers (3)

phimuemue
phimuemue

Reputation: 35983

I'm not an mac expert, but you can have a look over here.

Alternatively, you can try this.

Upvotes: 0

Ben Hocking
Ben Hocking

Reputation: 8072

If you create a bash file (don't forget to chmod a+x) and use ${1:6} that will strip the first six characters. For example, if you put this in tmp.sh:

echo ${1:6}

Then, type:

find . -name "*.jpg" -exec ./tmp.sh {} \;

To see the results. Notice that I'm stripping the first 6 to get rid of the leading "./". To strip off the first four, just use ${1:4} - note that ${1} is the first argument being passed in to the file.

Upvotes: 0

Laurynas Tretjakovas
Laurynas Tretjakovas

Reputation: 659

You can write a c++ application if you know c++

Get all the imiges in one folder and then run a loop that runs through each file with the help of this http://www.ozzu.com/programming-forum/directory-listing-t42574.html

Then rename the files using a c++ function rename(oldname, newname);

oldname, for example, will be 300_03e05a1f5fb83bc113edaa898b2c46f3.jpg and new name will be

string newname = ""; 
newname += oldname.substr(4, oldname.length() - 4);`

documentation on rename - .http://www.cplusplus.com/reference/clibrary/cstdio/rename/

another solution - http://wfco.de/macosx/Renamer4Mac

Upvotes: 1

Related Questions