paip.索引文件列表排序算法

paip.目录文件列表排序算法
paip.目录文件列表排序算法


----作者Attilax , 1466519819@qq.com---  
今天要给一个目录下文件排序。但是效果总是不WIN7的不同。它是按字符来排序的……




实际的排序是这样的。


先排列数字文件列表。按数字大小排。




然后非数字文件名列表……按字符比较来排。




FileSystemInfo [] files = dirinfo.GetFileSystemInfos();


System.Collections.Generic.List<FileInfo> li=toList(files);
 
 Comparison<FileInfo> com = new Comparison<FileInfo>(Compare);
 li.Sort(com);






























private int Compare(FileInfo info1, FileInfo info2)
{




    String filenameNoEx = Path.GetFileNameWithoutExtension(info1.Name);
    String filenameNoEx2 = Path.GetFileNameWithoutExtension(info2.Name);
    if( m.str.isNum(filenameNoEx))
        if (m.str.isNum(filenameNoEx2))
        {
            int one = Int32.Parse(filenameNoEx.ToString() );
            int two = Int32.Parse(filenameNoEx2.ToString() );
            if (two > one)
                return -1;
            else
                return 1;
        }
    //try
    //{
    //    int one = Int32.Parse(info1.Name.ToString().Replace(".jpg", ""));
    //    int two = Int32.Parse(info2.Name.ToString().Replace(".jpg", ""));
    //    if (two > one)
    //        return -1;
    //    else
    //        return 1;
    //}
    //catch (Exception ex) { }
    return 0;
    int result;
    CaseInsensitiveComparer ObjectCompare = new CaseInsensitiveComparer();
    result = ObjectCompare.Compare(info1.FullName, info2.FullName);
    return result;
}