C# 图标标注小工具-查看重复文件

目录

效果

项目

代码

下载


效果

项目

代码

复制代码
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Windows.Forms;

namespace ImageDuplicate
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string FolderPath = "";
        List<ImgFileInfo> ltFile = new List<ImgFileInfo>();

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();

            if (dialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            textBox1.Text = "";
            FolderPath = "";
            ltFile.Clear();
            dataGridView1.DataSource = null;

            Application.DoEvents();

            button1.Enabled = false;
            button2.Enabled = false;

            FolderPath = dialog.SelectedPath + @"\";
            textBox1.Text = FolderPath;

            DirectoryInfo root = new DirectoryInfo(FolderPath);

            foreach (FileInfo f in root.GetFiles())
            {
                ltFile.Add(new ImgFileInfo(f.Name, GetFileMD5(FolderPath + f.Name)));
            }

            //var sortlist = ltFile.OrderBy(o => o.md5).ToList();

            var listGroup = ltFile.GroupBy(o => o.md5)
                .Select(g => (new
                {
                    md5 = g.Key,
                    num = g.Count(),
                    fileName = string.Join(",", g.Select(d => d.fileName))
                }))
                .OrderByDescending(o => o.num)
                .ThenBy(o => o.md5)
                .ToList();

            dataGridView1.DataSource = listGroup;

            //自适应所有列的宽度
            //dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);

            dataGridView1.Columns[0].Width = 300;
            dataGridView1.Columns[1].Width = 50;
            dataGridView1.Columns[2].Width = 850;

            button1.Enabled = true;
            button2.Enabled = true;

        }

        public static string GetFileMD5(string path)
        {
            if (!System.IO.File.Exists(path)) return "";
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
            MD5CryptoServiceProvider md5Provider = new MD5CryptoServiceProvider();
            byte[] buffer = md5Provider.ComputeHash(fs);
            string resule = BitConverter.ToString(buffer);
            md5Provider.Clear();
            fs.Close();
            return resule;
        }

        /// <summary>
        /// 去重复
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {

        }
    }
}

下载

源码下载

相关推荐
-凌凌漆-26 分钟前
【Qt】QStringLiteral 介绍
开发语言·qt
程序员爱钓鱼27 分钟前
Go语言项目工程化 — 常见开发工具与 CI/CD 支持
开发语言·后端·golang·gin
澪-sl1 小时前
基于CNN的人脸关键点检测
人工智能·深度学习·神经网络·计算机视觉·cnn·视觉检测·卷积神经网络
军训猫猫头1 小时前
1.如何对多个控件进行高效的绑定 C#例子 WPF例子
开发语言·算法·c#·.net
真的想上岸啊1 小时前
学习C++、QT---18(C++ 记事本项目的stylesheet)
开发语言·c++·学习
明天好,会的1 小时前
跨平台ZeroMQ:在Rust中使用zmq库的完整指南
开发语言·后端·rust
丁劲犇2 小时前
用 Turbo Vision 2 为 Qt 6 控制台应用创建 TUI 字符 MainFrame
开发语言·c++·qt·tui·字符界面·curse
旷世奇才李先生2 小时前
Next.js 安装使用教程
开发语言·javascript·ecmascript
charlie1145141913 小时前
深入理解Qt的SetWindowsFlags函数
开发语言·c++·qt·原理分析
likeGhee4 小时前
python缓存装饰器实现方案
开发语言·python·缓存