Getting files recursively: skip files/directories that cannot be read?

后端 未结 4 1439
感情败类
感情败类 2021-01-18 06:11

I want to get all of the files in a directory in an array (including the files in subfolders)

string[] filePaths = Directory.GetFiles(@\"c:\\\",SearchOption.         


        
4条回答
  •  滥情空心
    2021-01-18 06:23

    try this :

    DirectoryInfo directory = new DirectoryInfo(@"c:\");
            DirectoryInfo[] folders = directory.GetDirectories("*", SearchOption.AllDirectories);
    
            List files = new List();
            foreach (DirectoryInfo info in folders)
            {
                foreach (FileInfo file in info.GetFiles())
                {
                    files.Add(file.Name);
                }
            }
    

提交回复
热议问题