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

        }
    }
}

下载

源码下载

相关推荐
苦学编程的谢2 分钟前
Mybatis_2
java·开发语言·后端·java-ee·mybatis
AndrewHZ20 分钟前
【图像处理基石】如何对遥感图像进行目标检测?
图像处理·人工智能·pytorch·目标检测·遥感图像·小目标检测·旋转目标检测
微小冷22 分钟前
Vimba相机二次开发教程,基于Python
开发语言·python·二次开发·相机开发·vimba相机·vimba
从0至135 分钟前
C++编程入门:从基础到复合类型
开发语言·c++
枫叶丹42 小时前
【Qt开发】信号与槽(二)-> 信号和槽的使用
开发语言·qt
中游鱼2 小时前
如何序列化和反序列化动态 XmlElement ?
windows·microsoft·c#
Vertira2 小时前
python 阿里云 安装 dashscope的简介、安装
开发语言·python
hqxstudying4 小时前
Java异常处理
java·开发语言·安全·异常
wjs20247 小时前
状态模式(State Pattern)
开发语言
我命由我123457 小时前
Kotlin 数据容器 - List(List 概述、创建 List、List 核心特性、List 元素访问、List 遍历)
java·开发语言·jvm·windows·java-ee·kotlin·list