- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
namespace AppendStrinAtBegin
{
class Program
{
static void ProcessDirectory(string path, string fileMask, Action<string> action)
{
Directory.EnumerateFiles(path, fileMask).ToList().ForEach(action);
Directory.EnumerateDirectories(path).ToList().ForEach
(
subDirectory => ProcessDirectory(subDirectory, fileMask, action)
);
}
static void Main(string[] args)
{
Console.WriteLine("Path FileMask AppendedString");
if (args.Length < 3)
return;
var appendedString = args.Skip(2).Aggregate((workingSentence, next) => workingSentence+ " " +next);
ProcessDirectory(args[0], args[1], (file) => ProcessFile(file, appendedString));
Console.WriteLine("Gun done");
}
static void ProcessFile(string file, string appendedStringAtBegin)
{
var fileLines = File.ReadAllLines(file, Encoding.GetEncoding(1251));
var fileResulted = fileLines.ToList();
fileResulted.Insert(0, appendedStringAtBegin);
File.WriteAllLines(file, fileResulted, Encoding.GetEncoding(1251));
}
}
}