Add script to find encoding problems in file names.
This commit is contained in:
parent
550c8889be
commit
71a9a0d910
1 changed files with 31 additions and 0 deletions
31
find-encoding-barfed-files.sh
Executable file
31
find-encoding-barfed-files.sh
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# list of encodings to try. (max 10)
|
||||||
|
enc=( latin1 windows-1252 )
|
||||||
|
|
||||||
|
while IFS= read -rd '' file <&3; do
|
||||||
|
base=${file##*/} dir=${file%/*}
|
||||||
|
|
||||||
|
# if converting from utf8 to utf8 succeeds, we'll assume the filename is ok.
|
||||||
|
iconv -f utf8 <<< "$base" >/dev/null 2>&1 && continue
|
||||||
|
|
||||||
|
# display the filename converted from each enc to utf8
|
||||||
|
printf 'In %s:\n' "$dir/"
|
||||||
|
for i in "${!enc[@]}"; do
|
||||||
|
name=$(iconv -f "${enc[i]}" <<< "$base")
|
||||||
|
printf '%2d - %-12s: %s\n' "$i" "${enc[i]}" "$name"
|
||||||
|
done
|
||||||
|
printf ' s - Skip\n'
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
read -p "? " -n1 ans
|
||||||
|
printf '\n'
|
||||||
|
if [[ $ans = [0-9] && ${enc[ans]} ]]; then
|
||||||
|
name=$(iconv -f "${enc[ans]}" <<< "$base")
|
||||||
|
mv -iv "$file" "$dir/$name"
|
||||||
|
break
|
||||||
|
elif [[ $ans = [Ss] ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done 3< <(LC_ALL=C find . -depth -name "*[![:print:][:space:]]*" -print0)
|
Loading…
Reference in a new issue