In my program c#, i am using LINQ to fetch all file from directory for processing as following
var FilesToProcess = from filePath in Directory.GetFiles(sDire
You can use the Linq GroupBy method to do this, eg:
DirectoryInfo directory = new DirectoryInfo(sDirectory);
var filePairs = directory
.GetFiles("*.xml")
.Union(directory.GetFiles("*.txt"))
.GroupBy(file => file.Name);
Or if you wish to get just the files in pairs:
var filePairs = directory
.GetFiles("*.xml")
.Union(directory.GetFiles("*.txt"))
.GroupBy(file => file.Name)
.Select(grp => new
{
XmlFile = grp.FirstOrDefault(file => file.Extension == "xml"),
TxtFile = grp.FirstOrDefault(file => file.Extension == "txt")
})
.Where(pair => pair.XmlFile != null && pair.TxtFile!= null);