コード例 #1
0
        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);

            }
        }
コード例 #2
0
        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;
        }