读取system32文件夹下的dll

heyangbin 2010-10-17 10:02:07
在.net1.0/2.0/3.0/3.5/4.0下编写一个函数,函数功能是实现读取system32文件夹下所有的dll的文件名,并按字典顺序保存到字符串数组中,函数返回该字符串数组。要求用一行代码实现,这个怎么搞呢?
...全文
109 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
叶子 2010-10-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 heyangbin 的回复:]
我是LZ,答案如下:

C# code

return from p in Directory.GetFiles(@"C:\Windows\system32") where p.EndsWith(".dll") select p;
[/Quote]

不错
ZengHD 2010-10-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 heyangbin 的回复:]

我是LZ,答案如下:
C# code

return from p in Directory.GetFiles(@"C:\Windows\system32") where p.EndsWith(".dll") select p;
[/Quote]

语法糖很高级啊

heyangbin 2010-10-18
  • 打赏
  • 举报
回复
我是LZ,答案如下:

return from p in Directory.GetFiles(@"C:\Windows\system32") where p.EndsWith(".dll") select p;
wuyq11 2010-10-17
  • 打赏
  • 举报
回复
List<FileInfo> lst=new List<FileInfo>();

foreach (string file in System.IO.Directory.GetFiles("", "*.dll", System.IO.SearchOption.AllDirectories))
{
lst.Add(new FileInfo(file));
}
var result=from r in lst
orderby r.Name
select r;或
System.IO.DirectoryInfo di = new DirectoryInfo(dirPath);
FileInfo[] fi = di.GetFiles();
Array.Sort(fi, new FileInfoCompare());

public class FileInfoCompare : IComparer<FileInfo>
{
public int Compare(FileInfo x, FileInfo y)
{
return x.Name.Compare(y.Name);
}
}

ysz89757 2010-10-17
  • 打赏
  • 举报
回复
DirectoryInfo的GetFiles()
ZengHD 2010-10-17
  • 打赏
  • 举报
回复
string[] arrDLL = Directory.GetFiles(@"C:\Windows\System32\", "*.dll", SearchOption.AllDirectories);

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧