How to recursively list all the files in a directory in C#?

前端 未结 22 2527
长发绾君心
长发绾君心 2020-11-22 00:07

How to recursively list all the files in a directory and child directories in C#?

22条回答
  •  难免孤独
    2020-11-22 00:47

    private void GetFiles(DirectoryInfo dir, ref List files)
    {
        try
        {
            files.AddRange(dir.GetFiles());
            DirectoryInfo[] dirs = dir.GetDirectories();
            foreach (var d in dirs)
            {
                GetFiles(d, ref files);
            }
        }
        catch (Exception e)
        {
    
        }
    }
    

提交回复
热议问题