/correct-filenames.sh Secret
Created
October 12, 2013 15:53
Star
You must be signed in to star a gist
Correct weird encoding of Polish special characters in filenames recursively in the current directory
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
#!/bin/bash | |
replacements=\ | |
"-e s/ą/ą/g "\ | |
"-e s/ć/ć/g "\ | |
"-e s/ę/ę/g "\ | |
"-e s/ń/ń/g "\ | |
"-e s/ś/ś/g "\ | |
"-e s/ó/ó/g "\ | |
"-e s/ź/ź/g "\ | |
"-e s/ż/ż/g " | |
for file in `find . -type f`; do | |
correct_fn=$(echo "$file" | sed $replacements) | |
mv "$file" "$correct_fn" | |
done |
It lacks support for whitespace in filenames. This fixes that (includes develth's "fix" as well). I added verbose (-v) to mv, feel free to remove it. Many thanks for the original idea.
find . -type f | while read file; do
correct_fn="$(echo "$file" | sed $replacements)"
if [ "$file" != "$correct_fn" ]; then
mv -v "$file" "$correct_fn"
fi
done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following would prevent unnecessary renames: