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"
本文介绍了一个Shell脚本,用于递归修改指定文件夹下所有文件的编码为UTF-8。脚本中使用了enca工具来检测并修改文件编码,提供了两种使用方式:直接调用脚本或先设置默认路径。脚本适用于Linux环境。
5万+

被折叠的 条评论
为什么被折叠?



