• 大小: 171KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: 其他
  • 标签: 编码转换  

资源简介

详细使用及代码说明请参照我的blog http://www.cnblogs.com/geeking/

资源截图

代码片段和文件信息

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;
using NonCodeNet;
using System.Threading;
namespace iEncode
{
    public partial class Form1 : Form
    {
        private NonCodeNet.NonCodeClass objNonCode = new NonCodeNet.NonCodeClass();
        public Form1()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
        }
        public string getFileEncoding(string filePath)
        {
            string uni = string.Empty;
            Stream stream = File.Open(filePath FileMode.Open FileAccess.Read);
            BinaryReader binReader = new BinaryReader(stream);
            byte[] dat = new byte[stream.Length];
            binReader.Read(dat 0 dat.Length);

            String cod = objNonCode.GetCodeName(ref dat false);
            uni = changeCode(cod);

            binReader.Close();
            stream.Close();
            return uni;
        }
        private string changeCode(string cod)
        {
            string uni = string.Empty;
            switch (cod)
            {
                case “SJIS“:
                    uni = “shift-jis“;
                    break;
                case “JIS“:
                    uni = “iso-2022-jp“;
                    break;
                case “EUC“:
                    uni = “euc-jp“;
                    break;
                case “UNICODE“:
                    uni = “utf-16“;
                    break;
                case “UTF7“:
                    uni = “utf-7“;
                    break;
                case “UTF8“:
                    uni = “utf-8“;
                    break;
                //case “BIN“:
                //    uni = ““;
                //    break;
                default:
                    uni = “utf-8“;
                    break;
            }
            return uni;
        }
        private void btn_file_Click(object sender EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = “c/c++|*.c;*.h;*.cpp|ALL|*.*“;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                tbox_file.Text = ofd.FileName;
                //rtbox_log.Text = getFileEncoding(tbox_file.Text);
            }
        }

        List fileList = new List();
        private void getAllByPath(string path)
        {
            if (path.EndsWith(“\\“))
            {
                fileList.Add(path);
            }
            else
            {
                fileList.Add(path + “\\“);
            }

            string[] dirs = Directory.GetDirectories(path);
            fileList.AddRange(Directory.GetFiles(path));
            foreach (string dir in dirs)
            {
                getAllByPath(dir.ToString());
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      62464  2014-10-08 11:03  iEncode\iEncode\bin\Debug\iEncode.exe

     文件      34304  2014-10-08 11:03  iEncode\iEncode\bin\Debug\iEncode.pdb

     文件      14328  2014-10-08 11:03  iEncode\iEncode\bin\Debug\iEncode.vshost.exe

     文件      36864  2013-01-08 15:18  iEncode\iEncode\bin\Debug\NonCodeNet.dll

     文件      61440  2014-05-23 14:38  iEncode\iEncode\bin\Release\iEncode\iEncode.exe

     文件      36864  2013-01-08 15:18  iEncode\iEncode\bin\Release\iEncode\NonCodeNet.dll

    ....SH.       109  2014-05-23 14:38  iEncode\iEncode\bin\Release\iEncode\vssver2.scc

     文件      61952  2014-10-08 11:03  iEncode\iEncode\bin\Release\iEncode.exe

     文件      32256  2014-10-08 11:03  iEncode\iEncode\bin\Release\iEncode.pdb

     文件      14328  2014-10-17 13:51  iEncode\iEncode\bin\Release\iEncode.vshost.exe

     文件        490  2007-07-21 02:33  iEncode\iEncode\bin\Release\iEncode.vshost.exe.manifest

     文件      36864  2013-01-08 15:18  iEncode\iEncode\bin\Release\NonCodeNet.dll

    ....SH.       110  2014-05-23 14:39  iEncode\iEncode\bin\Release\vssver2.scc

     文件      13399  2014-10-17 13:51  iEncode\iEncode\Form1.cs

     文件      10235  2014-10-08 11:00  iEncode\iEncode\Form1.Designer.cs

     文件      39694  2014-10-08 11:00  iEncode\iEncode\Form1.resx

     文件       3951  2014-05-22 15:20  iEncode\iEncode\iEncode.csproj

     文件        516  2014-10-08 11:03  iEncode\iEncode\obj\Debug\iEncode.csproj.FileListAbsolute.txt

     文件        847  2014-10-08 11:03  iEncode\iEncode\obj\Debug\iEncode.csproj.GenerateResource.Cache

     文件      62464  2014-10-08 11:03  iEncode\iEncode\obj\Debug\iEncode.exe

     文件      22948  2014-10-08 11:03  iEncode\iEncode\obj\Debug\iEncode.Form1.resources

     文件      34304  2014-10-08 11:03  iEncode\iEncode\obj\Debug\iEncode.pdb

     文件        180  2014-05-22 15:21  iEncode\iEncode\obj\Debug\iEncode.Properties.Resources.resources

     文件       6176  2014-05-23 14:36  iEncode\iEncode\obj\Debug\ResolveAssemblyReference.cache

     文件        532  2014-10-17 13:51  iEncode\iEncode\obj\Release\iEncode.csproj.FileListAbsolute.txt

     文件        847  2014-10-08 11:00  iEncode\iEncode\obj\Release\iEncode.csproj.GenerateResource.Cache

     文件      61952  2014-10-08 11:03  iEncode\iEncode\obj\Release\iEncode.exe

     文件      22948  2014-10-08 11:00  iEncode\iEncode\obj\Release\iEncode.Form1.resources

     文件      32256  2014-10-08 11:03  iEncode\iEncode\obj\Release\iEncode.pdb

     文件        180  2014-05-22 15:21  iEncode\iEncode\obj\Release\iEncode.Properties.Resources.resources

............此处省略28个文件信息

评论

共有 条评论