static void Main(string[] args) { var options = new CommandlineOptions(); if (!Parser.Default.ParseArguments(args, options)) { //nonparsable arguments return; } var directoryPath = Path.GetFullPath(options.Path); var filePaths = Directory.EnumerateFiles(directoryPath); ulong count = 0; Parallel.ForEach(filePaths, path => { var file = new TextFile(path); file.Parse(); Console.WriteLine(path+": "+file.Words); lock (_locker) { count += file.Words; } }); Console.WriteLine(); Console.WriteLine("all words in all files: " + count); Console.ReadKey(); }
public ulong CountWords(string path) { var file = new TextFile(path); file.Parse(); return file.Words; }