Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a utility that can rename filters in multiple subfolders and then rename the files inside sequentially?

E.g. I select my-pictures and it'll do its magic and sequentially rename all the files in all the subfolders. For each new subfolder, the numbering resets to 1.

old structure

my-pictures (parent folder)
-- folder1
---- in-costa-rica.png
---- swimming-at-beach-costa-rica.png
-- panama-folder
---- panama-canal.png
---- with-witch-doctor.png

desired/new structure

my-pictures (parent folder)
-- folder1
---- 0001.png
---- 0002.png
-- panama-folder
---- 0001.png
---- 0002.png
share|improve this question
up vote 6 down vote accepted

The following lines in Terminal should do the trick

for dir in my-pictures/*; do
    if [[ -d "$dir" ]]; then
        cd "$dir"
        for file in *; do
            echo mv "$file" $(printf "%04d" $i).png
            (( i=i+1 ))
        cd -

I've put in an echo statement to suppress execution so you can test it first. If the output looks ok, just remove the echo and rerun.

This assumes that there are no more than 1000 files in each subfolder, none of the files is already renamed and that all of them are PNG pictures.

By default, files are sorted by name. If you want to sort by date, replace the second for statement with

for file in $(ls -t); do
share|improve this answer
thanks very much :) – mrjayviper Jan 2 '14 at 9:20

If you can do with selecting the individual sub-folders, there's an app for that. It might not do exactly what you desire but might save a lot of time nevertheless.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.