分类目录中的文件,并获得最高的文件名 [英] Sorting directory files and getting the highest file name

查看:135
本文介绍了分类目录中的文件,并获得最高的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有40个文件从0名称的目录,以39(例如),
我想获得的最多的文件在其名称(这意味着我需要得到39)
我想排序的目录..
我已经使用了以下主题试过:

I have a directory with 40 files with names from 0 to 39 (for example), I am trying to get the file with the largest number in its name (which means I need to get "39") I am trying to sort the directory.. I have tried using the following topics:

C# - 如何检索目录中的文件,按名称排序列表

分拣在C# Directory.GetFiles的结果。

Sorting the result of Directory.GetFiles in C#

没有什么工作对我来说..
我尝试每一种方法 - 使用LINQ和其他人..
和我不知道为什么..

Nothing works for me.. I tried each of the methods - using Linq and the others.. and I dunno why..

我得到的排序结果如下(请查看下图):

I get the following result of the sorting (check picture below):

感谢您的帮助,

锭的Bracha。

推荐答案

这是合乎逻辑的,他们会进行排序这样一来,你会带来一些语义按编号,对它进行排序,即解析所有的文件名以数字,然后通过这些文件进行排序。

It is only logical that they would be sorted that way, you would bring in some semantics to sort it by number, namely parse all the file names to numbers, then sort the files by that.

类似

files.OrderBy(path => Int32.Parse(Path.GetFileNameWithoutExtension(path)))

使用最后( )来获得最高编号的文件。

Use Last() to get the file with the highest number.

这篇关于分类目录中的文件,并获得最高的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆