Sometimes you end up having files that can't be opened or renamed in Dolphin (re. KDE bug #165044) because their name contains silly characters in some silly encoding. This is what Dolphin might offer to do in such a situation... if it were able to detect that such a situation had occured (which it isn't, according to the heated discussion under the linked-to bug report)
Remove silly characters from every filename in the current directory? (~/bin/unfuck-names)
#!/bin/bash
for a in *.*
do
b=$(echo "$a"|iconv -c) # strip characters that aren't valid under the default encoding
if [ "$a" != "$b" ] # check if any characters have been removed
then
c=1
while [ -f "$b" ] # check if the new filename is vacant
do
b="${b%.*}$c.${b##*.}" # generate a new name otherwise
c=$(( c + 1 ))
done
mv -n "$a" "$b"
fi
done
Comments
jakob
Fri, 07/01/2011 - 22:17
Permalink
convmv
The script above simply removes off characters - if you know in which encoding the filenames are coded, use
convmv, i.e.convmv -f latin1 -t utf-8 *.*will convert filenames in the current directory from latin1 (aka ISO-8859-1) to UTF-8.
Add new comment