with the following code , I can merge text files which exist in a directory
var allLines = Directory.GetFiles(directory, "*.txt")
.SelectMany(f => File.ReadLines(f));
File.WriteAllLines(outputFileName, allLines);
How can I modify it to merge files which date creation is today ?
DirectoryInfo info = new DirectoryInfo("");
FileInfo[] files = info.GetFiles().OrderBy(p => p.CreationTime).ToArray();
How can I combine the piece of code ?
DirectoryInfo info = new DirectoryInfo(directory);
var allLines = info.GetFiles("*.txt")
.Where(p => p.CreationTime.Date == DateTime.Today)
.OrderBy(p => p.CreationTime)
.SelectMany(p => File.ReadAllLines(p.FullName));
File.WriteAllLines(outputFileName, allLines);
Use File.GetCreationTime method:
var allLines = Directory.EnumerateFiles(directory, "*.txt", SearchOption.TopDirectoryOnly)
.Where(path => File.GetCreationTime(path).Date == DateTime.Today)
.SelectMany(f => File.ReadLines(f));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With