Home > DeveloperSection > Forums > FileInfo - Select one File out of one FileInfo[]
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    February-04-2014 5:39 AM

 C# C# 
Ratings:


 1 Reply(s)
 1066  View(s)
Rate this:

I have two FileInfo[] Array's and i want compare the Files with identical Names about their File Size and Last Modified Date. But how can i select a File out of a FileInfo[] with a specific Name?

My Code doesnt work, because i cant use FileInfo.Select to get a new FileInfo out. Any clues?

        foreach (FileInfo origFile in fiArrOri6)

        {

            FileInfo destFile = fiArrNew6.Select(file => file.Name == origFile.Name);

            if (origFile.Length != destFile.Length || origFile.LastWriteTime != destFile.LastWriteTime)

            {

                //do sth.

            }

        }

Thanks for any help :)

Any other charming solution for this Problem would be great. btw. #2 : does someone has good learning material for FileInfo?



Pravesh Singh

Total Post:411

Points:2881
Posted on    February-04-2014 5:58 AM

Hi Jayprakash,

You could use the FirstOrDefault that takes a filter

FileInfo destFile = fiArrNew6.FirstOrDefault(file => file.Name == origFile.Name);

Or, if you don't want the default, you can use the equivalent First that takes a filter

FileInfo destFile = fiArrNew6.First(file => file.Name == origFile.Name);


Don't want to miss updates? Please click the below button!

Follow MindStick