• 大小: 68KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-07-24
  • 语言: C#
  • 标签: Webzip  乱码  

资源简介

Webzip下载时的中文路径会变成乱码。自己用C#做了个改名的工具。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WebZipRename
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            RenameFolder(textBox1.Text);
            MessageBox.Show(“执行完成“);
        }
        private static bool IsUTF8Bytes(byte[] data) 
        { 
            int charByteCounter = 1; //计算当前正分析的字符应还有的字节数 
            byte curByte; //当前分析的字节. 
            for (int i = 0; i < data.Length; i++) 
            { 
                curByte = data[i]; 
                if (charByteCounter == 1) 
                { 
                    if (curByte >= 0x80) 
                    { 
                        //判断当前 
                        while (((curByte <<= 1) & 0x80) != 0) 
                        { 
                            charByteCounter++; 
                        } 
                        //标记位首位若为非0 则至少以2个1开始 如:110XXXXX...........1111110X 
                        if (charByteCounter == 1 || charByteCounter > 6) 
                        { 
                        return false; 
                        } 
                    } 
                } 
                else 
                { 
                    //若是UTF-8 此时第一位必须为1 
                    if ((curByte & 0xC0) != 0x80) 
                    { 
                    return false; 
                    } 
                    charByteCounter--; 
                } 
            } 
            if (charByteCounter > 1) 
            { 
                throw new Exception(“非预期的byte格式“); 
            } 
            return true; 
        } 
        private String UTF82GB(String v)
        {
            //声明字符集   
            System.Text.Encoding utf8 gb2312;
            //utf8   
            utf8 = System.Text.Encoding.GetEncoding(“utf-8“);
            //gb2312   
            gb2312 = System.Text.Encoding.GetEncoding(“gb2312“);
            byte[] utf;
            utf = gb2312.GetBytes(v);
            if (IsUTF8Bytes(utf))
            {
                utf = System.Text.Encoding.Convert(utf8 gb2312 utf);
                
            //返回转换后的字符   
                return gb2312.GetString(utf);
            }
            return v;
        }
        private void RenameFile(String source)
        {
            string sFile = Path.GetFileName(source);
            string sObj = UTF82GB(sFile);
            string sPath = Path.GetDirectoryName(source);
            string sNewDirectory = Path.Combine(sPath sObj );
            if(source!=sNewDirectory)
                File.Move(source sNewDirectory);   
        }
        private void RenameFolder(String folder)
        {
            if (Directory.Exists(fold

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-10-09 20:34  WebZipRename\
     文件        2711  2015-10-09 20:36  WebZipRename\Form1.Designer.cs
     文件        4057  2015-10-09 21:06  WebZipRename\Form1.cs
     文件        5817  2015-10-09 20:36  WebZipRename\Form1.resx
     文件         493  2015-10-09 20:34  WebZipRename\Program.cs
     目录           0  2015-10-09 20:34  WebZipRename\Properties\
     文件        1356  2015-10-09 20:34  WebZipRename\Properties\AssemblyInfo.cs
     文件        2876  2015-10-09 20:34  WebZipRename\Properties\Resources.Designer.cs
     文件        5612  2015-10-09 20:34  WebZipRename\Properties\Resources.resx
     文件        1099  2015-10-09 20:34  WebZipRename\Properties\Settings.Designer.cs
     文件         249  2015-10-09 20:34  WebZipRename\Properties\Settings.settings
     文件        3683  2015-10-09 20:50  WebZipRename\WebZipRename.csproj
     文件         865  2015-10-09 20:34  WebZipRename\WebZipRename.sln
     文件       30208  2015-10-09 21:06  WebZipRename\WebZipRename.suo
     目录           0  2015-10-09 21:18  WebZipRename\bin\
     目录           0  2015-10-09 21:06  WebZipRename\bin\Debug\
     文件        9728  2015-10-09 21:06  WebZipRename\bin\Debug\WebZipRename.exe
     文件       24064  2015-10-09 21:06  WebZipRename\bin\Debug\WebZipRename.pdb
     文件       11600  2015-10-09 21:06  WebZipRename\bin\Debug\WebZipRename.vshost.exe
     文件         490  2012-06-02 22:34  WebZipRename\bin\Debug\WebZipRename.vshost.exe.manifest
     目录           0  2015-10-09 21:09  WebZipRename\bin\Release\
     文件        9216  2015-10-09 21:06  WebZipRename\bin\Release\WebZipRename.exe
     文件       11600  2015-10-09 21:06  WebZipRename\bin\Release\WebZipRename.vshost.exe
     目录           0  2015-10-09 20:34  WebZipRename\obj\
     目录           0  2015-10-09 21:06  WebZipRename\obj\x86\
     目录           0  2015-10-09 21:06  WebZipRename\obj\x86\Debug\
     文件        5420  2015-10-09 21:02  WebZipRename\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6314  2015-10-09 21:06  WebZipRename\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2015-10-09 21:19  WebZipRename\obj\x86\Debug\TempPE\
     文件         180  2015-10-09 21:06  WebZipRename\obj\x86\Debug\WebZipRename.Form1.resources
     文件         180  2015-10-09 21:06  WebZipRename\obj\x86\Debug\WebZipRename.Properties.Resources.resources
............此处省略13个文件信息

评论

共有 条评论