```
FileInfo[] folderFiles = folder.GetFiles();

foreach (FileInfo file in folderFiles)
{

    int fileCount = 0;

    StreamWriter sw = null;

    string fileName = Path.GetFileNameWithoutExtension(file.Name);

    string[] brkedfilename = fileName.Split('_');

    string stringToCheck = brkedfilename[3];

    for (int i = 0; i <= folderFiles.Count() - 1; i++)
    {
        string fileName2 = folderFiles[i].Name;

        string[] brkedfilename2 = fileName2.Split('_');

        if (brkedfilename2[3] == stringToCheck)
        {
            fileCount = ++fileCount;

            if (fileCount == 2)
           {
                sw = new StreamWriter(folderPath + "/" + newFileName, true);
                sw.WriteLine(stringToCheck + "  " + "--" + "  " + "Repeated in folder " + " " + folder.Name);
                sw.Close();
            }
        }
    }
}

```

By doing this way, if a file name is existing 2 times , it is writing that file name 2 times. But I want it to write only once.

Any help would be appreciated. Thanks in advance. :)