Hello!
My code looks for txt files and prints lines containing the values of regular expressions specified in this code to the console.
I would like to add a condition that allows me to search files for a specific date.
I commented out my attempt..
Could you help me to add a search "date condition" in this code?
My code looks for txt files and prints lines containing the values of regular expressions specified in this code to the console.
I would like to add a condition that allows me to search files for a specific date.
I commented out my attempt..
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string rootFolder = @"C:\Users\Anton\Desktop\?#folder";
string pattern = @"\b(Nina|Ira|Sveta)\b";
foreach (var file in Directory.EnumerateFiles(rootFolder, "*.txt", SearchOption.AllDirectories))
{
using (StreamReader sr = new StreamReader(file, System.Text.Encoding.Default))
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (Regex.IsMatch(line, pattern, RegexOptions.IgnoreCase))
Console.WriteLine(file + " " + line);
}
}
}
Console.ReadKey();
}
}
}
Could you help me to add a search "date condition" in this code?
Last edited by a moderator: