星期五, 9月 22, 2006

檔名 big5 -> utf8

常常去下載東西(音樂, 影片..)
別人都會用big5 來編碼, 用起來很麻煩
於是我寫了個小script, 把目錄下big5 -> utf8 檔名

想要參考看看的可以觀看全文 :D

#!/bin/bash
ls > olist
iconv -f big5 -t utf8 olist -c > nlist
#iconv -f gb2312 -t utf8 olist -c > nlist
i=1
until [ -z $(sed -n "$i"p olist) ]
do
olist="$(sed -n "$i"p olist)"
nlist="$(sed -n "$i"p nlist)"
if [ "$olist" != "$nlist" ]
then
mv $olist $nlist
fi
i=$(($i+1))
done

基本上就是這樣, 大概也不會有什麼問題..
只不過有些時候會有些字元轉不過來, 會怪怪的

沒有留言: