public DirectoriesScanner(string path) { if (File.Exists(path)) { try { string extension = Path.GetExtension(path); Console.WriteLine("the extension is " + extension); if (extension == ".txt") { FileAnalyser t = new FileAnalyser(path); } if (extension == ".cs" || extension == ".java") { ProgramAnalyser pa = new ProgramAnalyser(path); pa.printCount(); } else { Console.WriteLine("This extension " + extension + " is not supported"); } } catch (IOException) { Console.WriteLine("Sometinhg wrong happen, check the filename.No space is allowed"); } } else if (Directory.Exists(path)) { this.ReadDirectoryContent(path); } }
private int ReadDirectoryContent(string targetDirectory) { int countTotal = 0; string[] filesEntries = Directory.GetFiles(targetDirectory); foreach (String fileName in filesEntries) { ProgramAnalyser file = new ProgramAnalyser(fileName); countTotal += file.CountLine(); } string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory); foreach (string subdirectory in subdirectoryEntries) { ReadDirectoryContent(subdirectory); } return countTotal; }