首页 > 代码库 > 遍历文件夹下java文件utf-8编码转gbk编码,解决source insight无法查看中文的错误

遍历文件夹下java文件utf-8编码转gbk编码,解决source insight无法查看中文的错误

#!/bin/sh

function conv() {
	if [ "$(expr match "$1" ".*\.java$")" != "0" ]; then
		echo "Converting $1 ..."
		iconv -f utf-8 -t gbk $1 > $1.temp
		rm $1
		mv $1.temp $1
	else
		echo "Skip $1"
	fi
}

#深度优先方式遍历参数$1指定的目录并逐文件进行转码
function walk() {
for file in `ls $1`
	do 
		if [ -d $1"/"$file ]
		then 
			walk $1"/"$file
		else 
			conv $1"/"$file
		fi
	done
}

read -p "继续执行本程序可能会破坏您的源码,请确认是否继续?<yes/no>:" key
if [ "$key" != "yes" ]; then
	exit 0
else
	walk $1
fi
exit 0

遍历文件夹下java文件utf-8编码转gbk编码,解决source insight无法查看中文的错误