How to read File names recursively from subfolder using LINQ

前端 未结 5 1185
鱼传尺愫
鱼传尺愫 2021-01-13 09:36

How to read file name with dll extension from a directory and from its subfolders recursively using LINQ or LAMBDA expression.

Now i\'m using Nested for

5条回答
  •  太阳男子
    2021-01-13 10:23

    this returns just file names+extensions:

    DirectoryInfo di = new DirectoryInfo(@"d:\somewhere\");
    var q = from i in di.GetFiles("*.dll", SearchOption.AllDirectories)
            select i.Name;
    

    this returns just file names without extensions:

    DirectoryInfo di = new DirectoryInfo(@"d:\somewhere\");
    var q = from i in di.GetFiles("*.dll", SearchOption.AllDirectories)
            select System.IO.Path.GetFileNameWithoutExtension(i.Name);
    

提交回复
热议问题