排序由OpenFileDialog检索的文件 [英] sorting files retrieved by OpenFileDialog

查看:72
本文介绍了排序由OpenFileDialog检索的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对OpenFileDialog检索多个

选定文件的顺序不满意。我希望它们在日期顺序中,从最旧到最新,但默认情况下

它们以文件名输入,从最后到第一位。


唯一似乎相关的属性是排序,所有这一切是颠倒

文件名顺序。我需要日期订单。我已经找到了答案但是

什么都没有出现。任何想法?

I''m not happy with the order in which OpenFileDialog retrieves multiple
selected files. I want them in Date order, oldest to newest, but by default
they come in by filename, last to first.

The only property that seems relevant is Sort, and all that does is invert
the filename order. I need Date order. I''ve searched for an answer but
nothing has come up. Any ideas?

推荐答案

看看以下是否有帮助

注意:没有编译它,所以可能有拼写错误或语法错误


''Comparer Class

Public Class CompareFileDates

实现IComparer

功能IComparer.Compare( ByVal a As Object,ByVal b As Object)As Integer

返回DateTime.Compare(System.Io.File.GetLastWriteTime(DirectCast(a,

String)),System .Io.File.GetLastWriteTime(DirectCast(b,String)))

结束功能

结束班级


''代码按日期排序文件

Array.Sort(文件,新的CompareFileDates());


HTH

rawCoder


" Randall Arnold" <太阳神*********** @ discussions.microsoft.com>在消息中写道

新闻:A1 ********************************** @ microsof t.com ...
See if the following helps
NOTE: Havent compiled it, so might have typo or syntax errors

'' Comparer Class
Public Class CompareFileDates
Implements IComparer
Function IComparer.Compare(ByVal a As Object, ByVal b As Object) As Integer
Return DateTime.Compare( System.Io.File.GetLastWriteTime(DirectCast(a,
String)) , System.Io.File.GetLastWriteTime(DirectCast(b, String)) )
End Function
End Class

'' Code to sort the files by date
Array.Sort(files, new CompareFileDates());

HTH
rawCoder

"Randall Arnold" <Ra***********@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
我对OpenFileDialog检索多个选定文件的顺序不满意。我希望它们按日期顺序,从最旧到最新,但是按
默认它们按文件名输入,从最后到第一个。

唯一相似的属性是Sort,所有这一切都是颠倒
文件名顺序。我需要日期订单。我找了一个答案,但没有提出任何问题。有什么想法吗?
I''m not happy with the order in which OpenFileDialog retrieves multiple
selected files. I want them in Date order, oldest to newest, but by default they come in by filename, last to first.

The only property that seems relevant is Sort, and all that does is invert
the filename order. I need Date order. I''ve searched for an answer but
nothing has come up. Any ideas?



" =?Utf-8?B?UmFuZGFsbCBBcm5vbGQ =?="

< Ra * **********@discussions.microsoft.com>写在

新闻:A1 ********************************** @ microsof t .com:
"=?Utf-8?B?UmFuZGFsbCBBcm5vbGQ=?="
<Ra***********@discussions.microsoft.com> wrote in
news:A1**********************************@microsof t.com:
我对OpenFileDialog检索多个选定文件的顺序不满意。我希望它们在日期顺序中,从最旧到最新,
但默认情况下它们以文件名输入,从最后到第一个。

唯一似乎相关的属性是Sort,所有这一切都是
反转文件名顺序。我需要日期订单。我找了一个
答案,但什么都没有出现。任何想法?
I''m not happy with the order in which OpenFileDialog retrieves
multiple selected files. I want them in Date order, oldest to newest,
but by default they come in by filename, last to first.

The only property that seems relevant is Sort, and all that does is
invert the filename order. I need Date order. I''ve searched for an
answer but nothing has come up. Any ideas?




我认为anwser将创建两个数组并将选定的文件

添加到一个数组中作为FileInfo(路径)和另一个数组为返回的每个项添加FileInfo

(路径).DateCreated,然后执行[Array] .Sort

(dateArray,fileInfoArray),生成的fileInfoArray将是按

dateArray排序。更多相关内容: http://msdn.microsoft.com/library/default.asp?

url = / library / en-us / cpref / html / frlrfsystemarrayclasssorttopic.asp


另一种方法是在类中实现IComparer(只有一个

函数)将所有选中的文件作为FileInfo抛出s然后

[数组] .Sort(fileInfoArray,ComparerClass)更多信息

这里: http://msdn.microsoft.com/library/de...l=/library/en-

us / cpref / html / frlrfsystemcollectionsicomparerclasstopic.asp



I think the anwser would be to create two arrays and add the selected files
to one array as FileInfo(path) and the other array add FileInfo
(path).DateCreated for each item returned, then do [Array].Sort
(dateArray,fileInfoArray), the resulting fileInfoArray will be sorted by
dateArray. More on this here:http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/cpref/html/frlrfsystemarrayclasssorttopic.asp

The other way would be to implement IComparer in a class (which is only one
function) throw all the selected files in an array as FileInfo''s and then
[Array].Sort(fileInfoArray,ComparerClass) More info
here:http://msdn.microsoft.com/library/de...l=/library/en-
us/cpref/html/frlrfsystemcollectionsicomparerclasstopic.asp


感谢您的快速回复!


这对我来说是外来的功能,并且在插入代码之后我收到了一些错误,所以我显然不得不玩它一点。我很高兴你让我开始了!


兰德尔


" rawCoder"写道:
Thanks for the quick response!

That''s foreign functionality to me and I received a number of errors after
inserting the code so I''m obviously going to have to play with it a bit. I
appreciate you getting me started!

Randall

"rawCoder" wrote:
看看以下是否有帮助
注意:没有编译它,所以可能有拼写错误或语法错误

''Comparer Class 实现IComparer
函数IComparer.Compare(ByVal a As Object,ByVal b As Object)As Integer
返回DateTime.Compare(System.Io.File.GetLastWriteTime(DirectCast) (a,
String)),System.Io.File.GetLastWriteTime(DirectCast(b,String)))
结束函数
结束类

''代码按日期排序文件
Array.Sort(文件,新的CompareFileDates());

HTH
rawCoder

Randall Arnold <太阳神*********** @ discussions.microsoft.com>在消息中写道
新闻:A1 ********************************** @ microsof t.com。 ..
See if the following helps
NOTE: Havent compiled it, so might have typo or syntax errors

'' Comparer Class
Public Class CompareFileDates
Implements IComparer
Function IComparer.Compare(ByVal a As Object, ByVal b As Object) As Integer
Return DateTime.Compare( System.Io.File.GetLastWriteTime(DirectCast(a,
String)) , System.Io.File.GetLastWriteTime(DirectCast(b, String)) )
End Function
End Class

'' Code to sort the files by date
Array.Sort(files, new CompareFileDates());

HTH
rawCoder

"Randall Arnold" <Ra***********@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
我对OpenFileDialog检索多个选定文件的顺序不满意。我希望它们按日期顺序,从最旧到最新,但是通过
I''m not happy with the order in which OpenFileDialog retrieves multiple
selected files. I want them in Date order, oldest to newest, but by


默认

它们按文件名输入,从最后到第一个。

唯一似乎相关的属性是Sort,所有这一切都是颠倒
文件名顺序。我需要日期订单。我找了一个答案,但没有提出任何问题。有什么想法?
they come in by filename, last to first.

The only property that seems relevant is Sort, and all that does is invert
the filename order. I need Date order. I''ve searched for an answer but
nothing has come up. Any ideas?




这篇关于排序由OpenFileDialog检索的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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