0

I will ask you to please explain your answer, as I'm not acquainted with this Library

So what I'm trying is to is get the text of all project items and count all lines. What is the best way is approaching this problem ?

AndrewToasterr
  • 459
  • 1
  • 5
  • 16
  • Can you provide an example of what you have attempted so far. – Jawad Dec 11 '19 at 16:40
  • Does this answer your question? [How to count all the lines of code in a directory recursively?](https://stackoverflow.com/questions/1358540/how-to-count-all-the-lines-of-code-in-a-directory-recursively) – Bizhan Dec 11 '19 at 16:42

1 Answers1

1

In order for you to get the count of all lines, you will need to recursively go through each folder and get the length of each files within them.


Process the directories recursively. Get the number of lines for text files and recursively call itself for more directories

    public static int GetTotalLinesInAllFiles(string targetDirectory)
    {
        int totalLines = 0;

        // Process the list of files found in the directory.
        foreach (string fileName in Directory.GetFiles(targetDirectory))
            totalLines += File.ReadAllLines(fileName).Length;

        // Recurse into subdirectories of this directory.
        foreach (string subdirectory in Directory.GetDirectories(targetDirectory))
            totalLines += GetTotalLinesInAllFiles(subdirectory);

        return totalLines;
    }

In your main function, you can start the call with

    ProcessDirectory(Environment.CurrentDirectory);
Jawad
  • 11,028
  • 3
  • 24
  • 37