change encoding of folder recusively

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"

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值