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

后端 未结 4 1436
感情败类
感情败类 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:32

    or try this one :

            DirectoryInfo dirs = new DirectoryInfo(@"c:\");
            List filenames = (from i in dirs.GetFiles("*", SearchOption.AllDirectories)
                                      select i.Name).ToList();
    

    or file names without extension :

            DirectoryInfo dirs = new DirectoryInfo@"c:\");
            List filenames = (from i in dirs.GetFiles("*", SearchOption.AllDirectories)
                                      select System.IO.Path.GetFileNameWithoutExtension(i.Name)).ToList();
    

提交回复
热议问题