How can I split a folder with thousands of images into multiple sub-folders?

bash, command-line, macos

Solution

`i=0; for f in *; do d=dir_$(printf %03d $((i/100+1))); mkdir -p $d; mv "$f" $d; let i++; done`

Problem

I have a directory with about 5000 images and I'd like to split/move it in to 50 folders (which will need to be created) with 100 images each. Is there a way to do this using terminal? I'm running OS X.

Original source