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)
        {

        }
    }
}

下载

源码下载

相关推荐
程序员老陆4 分钟前
嵌入式 Qt:QWidgets 还是 QML / Qt Quick?
开发语言·qt
.道阻且长.5 分钟前
C++11 :新的类功能,lambda,包装器
开发语言·c++·后端
言乐66 分钟前
JavaScript概括前端原理
开发语言·前端·javascript·python·ecmascript
liulilittle6 分钟前
短期内不存在通用 AI 工作流魔法
大数据·开发语言·c++·人工智能·llm·agent·tools
郝学胜-神的一滴23 分钟前
C++ Templates 03:手写一个Stack看透模板核心机制
开发语言·c++·产品运营·软件工程·产品经理
(Charon)37 分钟前
【C/C++面试】手写内存池:从空闲链表到内存申请与释放
java·开发语言·windows
UIU11438 分钟前
-7 / 2 在 C 里是 -3,在 Python 里是 -4,谁算错了?
c++·学习·c#
派小心.40 分钟前
页面关闭前埋点丢失:sendBeacon验收
开发语言·php
这张生成的图像能检测吗1 小时前
(论文速读)Object-Driven Multi-Layer Scene Decomposition:从单张图像恢复遮挡后的多层场景
人工智能·算法·计算机视觉·rgb-d·场景分解
YOLO数据集集合1 小时前
河道环境智能检测系统(YOLO + DeepSeek) | 河道巡检 YOLO DeepSeek 大语言模型 智慧水利 9144期
人工智能·yolo·目标检测·语言模型·河道污染·城市治理