How to find duplicate file name by omitting anything after hash (#)

I am trying to find all the file names that have the same names and wanted to group those similar file names with folder path and export them to a text file.

So far I have written the following codes which will allow me to find # inside every .png file name and successfully add the number after the #. But I am unable to check for duplicate names by skipping the # and number after that.

All of my file names are in .png format.

I have like more than 100 sub folders and every folder got around more than 2 files upto 25 files of .png.

File naming styles:

Unique Red Peach#11.png
Red Peach#11.png
Light Red-Mo Dragon#31.png
Killer Whale Tribute#11.png

Any suggestions are highly appreciated!!!

 private void button1_Click(object sender, EventArgs e)
            FolderBrowserDialog folderDlg = new FolderBrowserDialog();
            folderDlg.SelectedPath = "C:\\Users\\demo\\Documents\\process\\";
            if (folderDlg.ShowDialog() != DialogResult.OK)

            // Has different framework dependend implementations 
            // in order to handle unauthorized access to subfolders
        private void RenameAllPngFiles(string directoryPath)
            foreach (var item in GetDirectoryInfos(directoryPath))

        private void RenameCurrentPng(string directoryPath)
            int fileNameSuffixCounter = 1;
            foreach (string originalFullFileName in Directory.EnumerateFiles(directoryPath, "*.png"))
                string ShortFileName = System.IO.Path.GetFileNameWithoutExtension(originalFullFileName);
                if (!ShortFileName.Contains("#"))
                    // The new file name without path
                    var newFileName = $"{ShortFileName}#{fileNameSuffixCounter++}{System.IO.Path.GetExtension(originalFullFileName)}";
                    FileSystem.RenameFile(originalFullFileName, newFileName);

        private DirectoryInfo[] GetDirectoryInfos(string directoryPath)
            DirectoryInfo di = new DirectoryInfo(directoryPath);
            DirectoryInfo[] directories = di.GetDirectories("*", System.IO.SearchOption.AllDirectories);
            return directories;
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum