简体   繁体   English

EnvDTE - 如何从项目中的文件中获取文本

[英]EnvDTE - How to get the text from a file in a project

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 ?解决这个问题的最佳方法是什么?

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM