Created
April 23, 2012 15:15
-
-
Save anonymous/2471545 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for album in event-*/album-*/; do | |
echo "$album"; | |
# Execute every directory in its own shell, so we do not need to worry | |
# about "cd -" on errors, etc. | |
( | |
cd "$album"; | |
# Fill the positional parameter array with all files. "*" is expanded | |
# alphabetically by default. | |
set -- *; | |
# First, determine the number of digits to use for the zero-padded | |
# number. | |
num_digits=1; | |
while [ $# -gt $((10 ** $#)) ]; do | |
let num_digits++; | |
done; | |
# Rename all files. | |
i=0; | |
for file; do | |
let i++; | |
new_file="$(printf "%0${num_digits}d.%s" $i "${file##*.}")"; | |
# Unless they already have the right name. | |
[ "$new_file" = "$file" ] && continue; | |
# Make sure to ask before overwriting, and be verbose about the operation. | |
mv -vi "$file" "$new_file"; | |
done; | |
); | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment