自己寫的批量文件名簡繁轉換腳本。。。

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
dukelec
帖子: 405
注册时间: 2010-08-26 22:20
系统: Gentoo
来自: Canton
送出感谢: 3 次
接收感谢: 7 次

自己寫的批量文件名簡繁轉換腳本。。。

#1

帖子 dukelec » 2011-02-02 19:00

需要安裝 cconv,一個支持詞組轉換的工具,效果媲美同文堂。

代码: 全选

#!/bin/bash

current_path[0]="./"

process_cn2hk(){
    filename_original="$1"
    filename_hk=`echo "$filename_original" | cconv -f utf-8 -t utf8-hk`
    if [ "$filename_original" == "$filename_hk" ]; then
      echo ------------------------------------
      for var in ${current_path[@]};do
        echo -n "$var"
      done
      echo "$filename_original"
    else
      echo "++++++++++++++++++++++++++++++++++++"
      #
      echo -n "<-"
      for var in ${current_path[@]};do
        echo -n "$var"
      done
      echo "$filename_original"
      #
      echo -n "->"
      for var in ${current_path[@]};do
        echo -n "$var"
      done
      echo "$filename_hk"
      #
      mv "$filename_original" "$filename_hk"
    fi
}

duke_ergod()
{
  for x in *
  do
    process_cn2hk "$x"
  done
  #
  for x in *
  do
    if [ -d "$x" ];then
      cd "$x";
      current_path[${#current_path[@]}]="$x/"
      duke_ergod;
      cd ..
      unset current_path[${#current_path[@]}-1]
    fi
  done
}

  
if [ "$1" == "-all" ]; then

  duke_ergod

elif [ "$1" == "-nonce" ]; then

  for files in *
  do
    process_cn2hk "$files"
  done

else
  echo "change all: cn2hk -all"
  echo "change nonce: cn2hk -nonce"
fi
这些用户感谢了作者 dukelec 于这个帖子:
lilysirius (2016-12-16 8:29)
评价: 3.7%
回复

回到 “Shell脚本”