[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] private static extern int StrCmpLogicalW(string psz1, string psz2); /// <summary> /// 根据路径查到文件,按文件名称排序,智能排序,非ASCII码排序 /// </summary> /// <param name="pathToVersions"></param> /// <returns></returns> private static string[] GetFileListByPath(string pathToVersions) { var files = new DirectoryInfo(pathToVersions).GetFiles(); var list = files.ToList(); //根据修改时间排序,因为复制会改变创建时间,不会改变修改时间 //list.Sort((a, b) => b.LastWriteTime.CompareTo(a.LastWriteTime)); //list.Sort((a, b) => b.FullName.CompareTo(a.FullName)); //list = files.OrderBy(s => int.Parse(Regex.Match(Regex.Match(s.Name, @"\d+\.7z").Value,@"\d+").Value)).ToList(); //按windows的名称排序,abc_1.0.12.zip、abc_1.0.2.zip、abc_1.0.1.zip list.Sort((a, b) => StrCmpLogicalW(b.Name,a.Name)); return list.Select(d => d.FullName.Replace(pathToVersions + @"\", "")).ToArray(); }
按windows的文件名称排序,abc_1.0.12.zip、abc_1.0.2.zip、abc_1.0.1.zip,非ASCII码排序。可以调整入参的顺序,实现正序和倒序。例子中为倒序。
原文地址:https://www.cnblogs.com/zipon/p/11077266.html
时间: 2024-11-13 08:03:08