首页 > 编程语言 > 详细

文件名称排序

时间:2014-11-25 16:04:54      阅读:380      评论:0      收藏:0      [点我收藏+]

第一次写博客练习下

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();

文件名称排序

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!