urir10
My main question is not really how to parse the file name but how would i group them together. Lets say even the file name is only YYYYMMDD.txt nothing else.
Basically i have a method that zips the files. I want to be able to pass it a group of files based on their timestamp. So it will zip all file for Jan 1 together and all files for Jan 2 together etc.
You can try with the below code
//Change the file path here var directory = new DirectoryInfo("C:\\Test"); //Query to group by records based on DatePart var myFile = (from f in directory.GetFiles() .GroupBy(i => Regex.Replace(i.FullName, @"(.*?)(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})\.txt", "${year}/${month}/${day}")) select f).ToList(); //Read from grouping results foreach (var group in myFile) { foreach (var file in group) { string filename = file.FullName; //You can call the method here } }