码迷,mamicode.com
首页 > 编程语言 > 详细

文件名称排序

时间:2014-11-25 16:07:27      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:ar   sp   文件   div   log   bs   ef   as   new   

第一次写博客练习下

1 定义个文件比较类

public class FilesNameComparerClass :IComparer<string>
{

[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
private static extern int StrCmpLogicalW(string psz1, string psz2);

public int Compare(string x, string y)
{
return StrCmpLogicalW(x, y);
}
}

在Windows XP以后,资源管理器的文件名默认排序准则就调用了StrCmpLogicalW。
 C#中对的StrCmpLogicalW导入方法为:

       [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
       private static extern int StrCmpLogicalW(string psz1, string psz2);

2. 调用

  DirectoryInfo di = new DirectoryInfo(filePath);

  FileInfo[] fileList = di.GetFiles("*.*");

    fileList = fileList.OrderBy(s1 => s1.Name,new FilesNameComparerClass()).ToArray();

文件名称排序

标签:ar   sp   文件   div   log   bs   ef   as   new   

原文地址:http://www.cnblogs.com/kekekexin/p/4120931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!