Mac OS: how could I rename a file like APP_001.gif to 01.gif?

0

I have a load of files in a directory. They all have names like:

APP_001.gif
APP_101.gif

How could I bulk rename them to

01.gif
101.gif

i.e. get rid of the prefix before _, and then remove the first leading zero?

Thanks!

AP257

Posted 2011-02-10T22:14:19.573

Reputation: 33

1Are all prefixes the same APP_, or different? – Daniel Beck – 2011-02-10T22:17:15.883

Answers

4

for file in APP_*.gif; do
    new=${file#APP_}
    new=${new#0}
    mv "$file" "$new"
done

user1686

Posted 2011-02-10T22:14:19.573

Reputation: 283 655

1

shopt -s extglob; for f in in APP_*.gif; do mv "$f" "${f##app_?(0)}"; done

Paused until further notice.

Posted 2011-02-10T22:14:19.573

Reputation: 86 075

0

If the actual names are not important, and simply want all of the photos to have unique, yet organized names, you can open automator and create the following automator action.

This is what I do, and then save it as a service (assuming you have 10.6, snow leopard) then you can select any group of files in finder, right click and select . This version prompts the user for the prefix of each file then uses that value (instructions on referencing a variable in an automator action here), but you can also use the rename action alone to number files sequentially.

Numerize

finiteloop

Posted 2011-02-10T22:14:19.573

Reputation: 1 743

Why a down-vote? I answered the question. – finiteloop – 2011-02-10T22:52:09.577

The numbers seem to be relevant. Otherwise it'd be a simple "how do I make these sequential" question. – Daniel Beck – 2011-02-11T06:26:33.760