解压缩导致的文件名乱码,根本原因是不同语言系统用的编码不同,以及zip压缩不保存编码导致,zip默认用系统编码压缩。所以当在A系统系统以X编码压缩的文件,到B系统以Y编码解压后就会乱码。
比如日文系统:932 日文(Shift-JIS)
中文系统:936 中国 - 简体中文(GB2312)
查询编码在windows cmd 模式下,输入命令 : chcp
C:\Users\xxxxx>chcp
活动代码页: 936
解决方法1:解压的时候追加编码参数 -mcp=932
D:\picture>"C:\Program Files\7-Zip\7z.exe" x "日文.zip" -mcp=932
解决方法2:如果已经解压完了,直接用下面脚本修改文件名
PowerShell脚本
为了防止重复执行导致的再次乱码,追加防止重复操作:
Function Func-Rename($a,$b){
$TRUE_FALSE=(Test-Path tmprename.txt)
if($TRUE_FALSE -eq "True")
{
throw "do not repeat"
}
else
{
New-Item tmprename.txt -type file
}
$gbk = [Text.Encoding]::GetEncoding(936);
$jis = [Text.Encoding]::GetEncoding(932);
dir -r | % {
$newname = $jis.GetString($gbk.GetBytes($_.name));
$fullpath = Split-Path -parent $_.fullname
$newnamepath = Join-Path $fullpath $newname
if ($_.name -ne $newname) {
echo $_.fullname
echo $newnamepath
ren $_.fullname $newnamepath;
}
}
}
Func-Rename