zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    c/c++设置图片为透明图
    转;说说AngularJS中的$parse和$eval
    转: css3: display:box详解
    转: 深入理解 AngularJS 的 Scope
    转:说说angularjs中的$parse和$eval
    转: 理解AngularJS中的依赖注入
    angularjs学习总结(快速预览版)
    XML基础知识
    读书笔记:js设计模式
    contains 和 ele.compareDocumentPosition确定html节点间的关系
  • 原文地址:https://www.cnblogs.com/attilax/p/15199724.html
Copyright © 2011-2022 走看看