locked
find duplicate excel filenames(extensions are different like xls and xlsx) in a folder using c# RRS feed

  • General discussion

  • I have a folder and 10 files. In those files, two files are like wilson.xls and wilson.xlsx. these are duplicate files.

    now duplicate filename wilson should be assisgned to a variable. this should be done in script task. could any body give C# code.

    if multiple duplicate files like wilson and jacky, then output will be wilson,jacky will be assigned to variable

    Thursday, July 30, 2020 12:53 PM

All replies

  • Hi TangiralaReddy,

    First, please change your post type from Discussion to a Question.

    Here is how to do it.

    c#:

    void Main()
    {
    	const string directory = @"e:\temp";
    	const string fileWildcard = "*.xl*";
    	const string separator = ",";
    
    	DirectoryInfo sourceDir = new DirectoryInfo(directory);
    	FileInfo[] fileList = sourceDir.GetFiles(fileWildcard);
    
    	var queryDupNames =
    			from file in fileList
    			group file.Name by Path.GetFileNameWithoutExtension(file.Name) into fileGroup
    			where fileGroup.Count() > 1
    			select fileGroup;
    
    	// convert into a separator concatenated string
    	string dupFiles = String.Join(separator, queryDupNames.Select(dn => dn.Key));
    }


    Thursday, July 30, 2020 10:50 PM
  • Hi TangiralaReddy,

    What's the latest?

    Were you able to resolve the issue based on the proposed solution?

    Tuesday, August 4, 2020 5:57 PM