开发者

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 开发者_Go百科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


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


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.


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

Alternatively, you can try this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜