C# directory.getfiles memory help

前端 未结 5 1895
梦毁少年i
梦毁少年i 2020-12-11 20:05

Here is the code I’m using:

using (StreamWriter output = new StreamWriter(Path.Combine(masterdestination, \"Master.txt\")))
{
     string masterfolders = sou         


        
5条回答
  •  我在风中等你
    2020-12-11 20:48

    Directory.GetFiles really sucks. If you can use .NET 4.0 you should look into using Directory.EnumerateFiles. From the docs:

    The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array. Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.

提交回复
热议问题