static void Main(string[] args) { while (true) { Console.WriteLine("Press Q to quit or any other key to continue"); ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.Q) { break; } Console.Write(Environment.NewLine); Console.Write("Enter your inputs (directory) (file name/identifier) (base name for generated files): "); string input = Console.ReadLine(); string[] input_args = new string[3]; // Extract arguments from the string. An argument is anything enclosed by quotes // or separated by spaces but not enclosed by quotes try { int i = 0; while (!string.IsNullOrEmpty(input)) { input = input.Trim(); // argument enclosed by quotes if (input[0] == '\"') { int arg_start = input.IndexOf('\"'); int arg_end = input.NextIndexOf('\"', arg_start + 1); string arg = input.IndexSubstring(arg_start, arg_end); arg = arg.Trim('\"'); input = input.IndexRemove(arg_start, arg_end); input_args[i] = arg; i++; } else { int arg_end = input.IndexOf(' '); string arg = ""; if (arg_end == -1) { arg = input; input = input.Remove(0); } else { arg = input.IndexSubstring(0, arg_end); input = input.IndexRemove(0, arg_end); } arg = arg.Trim(); input_args[i] = arg; i++; } } } catch (Exception e) { Console.WriteLine(e.Message); continue; } // check for the right number of arguments foreach (var arg in input_args) { if (arg == null) { Console.WriteLine("An error occured: incorrect number of inputs"); continue; } } // regex with expression that'll be used to filter files Regex name_checker = new Regex(string.Format("({0})", input_args[1])); List <string> file_names; // get all files in the input directory try { file_names = Directory.EnumerateFiles(input_args[0]).ToList(); } catch (Exception e) { Console.WriteLine(e.Message); continue; } // get the files that match the input expression GeneralHelpers.FindMatchingStrings(file_names, name_checker); // read the files and generate the long distance files for (int i = 0; i < file_names.Count; i++) { string contents = File.ReadAllText(Path.Combine(input_args[0], file_names[i])); string[] contents_array = contents.Trim().Split(' '); GenerateLongDistanceFile(input_args[2], i + 1, contents_array); } Console.WriteLine("Success!"); Console.Write(Environment.NewLine); } }