change encoding of folder recusively
程序员文章站
2022-06-05 18:21:36
...
use shell to change encodeing of files under a folder recusively,
the script use a tool called "enca", install it if not yet,
there will be error info during execution, ignore that, it doesnot matter,
encode_util.sh:
#! /bin/bash # change encode of files to utf8 recusively # # how to use: # way 1: # just call: # encode_util.sh path # way 2: # modify the "default_path" variable first, # then call: # encode_util.sh # # the default folder to be encoded recusively, default_path="/media/ERIC_/knowledge/hardware/single chip/R2_disk" # encode files in a folder, recusively, do_encode() { base_dir="$1" do_encode_no_recu "$base_dir" for sub_dir in "$base_dir"/*;do if [ -d "$sub_dir" ];then do_encode "$sub_dir" fi done } # encode files in a folder, not recusively, do_encode_no_recu() { cd "$1" pwd enca -r -L zh_CN -x utf-8 * } # try get path from param path="" if [ -d "$1" ]; then path="$1"; else path="$default_path" fi echo "base path: $path" do_encode "$path"