Omdøb filer med underlige navne

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

Tags:

Comments

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

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Markdown

  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.