You can make several try-catch blocks in order not to fly out with an error, and get the files using Directory.GetFiles :
try { var txtFiles = Directory .GetFiles("C:\\path", "*.txt", SearchOption.AllDirectories) .ToList(); txtFiles.ForEach(file => { try { var oldText = File.ReadAllText(file); File.WriteAllText(file, oldText.Replace("match", "new value")); Console.WriteLine(@"Π’Π΅ΠΊΡΡ Π² ΡΠ°ΠΉΠ»Π΅ '{0}' ΡΡΠΏΠ΅ΡΠ½ΠΎ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½.", file); } catch (Exception exception) { Console.WriteLine(@"ΠΡΠΈΠ±ΠΊΠ° ΡΡΠ΅Π½ΠΈΡ/Π·Π°ΠΏΠΈΡΠΈ ΡΠ°ΠΉΠ»Π° '{0}' {1}", file, exception.Message); } }); } catch (Exception exception) { Console.WriteLine(@"ΠΡΠΈΠ±ΠΊΠ° ΠΏΠΎΠ»ΡΡΠ΅Π½ΠΈΡ ΡΠΏΠΈΡΠΊΠ° ΡΠ°ΠΉΠ»ΠΎΠ². Error: {0}", exception.Message); }
File.ReadAllText
methodFile.ReadAllText
not have an overload that takes two arguments of typeString
. - Dmitry