![](/img/trans.png)
[英]vb.net how to list collection of files in a directory, in reverse alphanumeric order same as File Explorer > Name descending
[英]VB.NET Sort files in directory by alphanumeric
如何使用字母数字对下面此目录中的文件进行排序? 文件示例:12325_2011.jpg
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim di As New IO.DirectoryInfo(ImagePath)
Dim imageArray As IO.FileInfo() = di.GetFiles()
Dim image As IO.FileInfo
'list the names of all images in the specified directory
For Each image In imageArray
CheckBoxList1.Items.Add(image.Name)
Next
End If
End Sub
只需像这样修改现有的For Each循环:
For Each image In imageArray.OrderBy(Function(i) i.Name)
CheckBoxList1.Items.Add(image.Name)
Next
您可以使用排序列表类而不是图像数组:
http://msdn.microsoft.com/en-us/library/system.collections.sortedlist.aspx
例如
For each Item in di.GetFiles
'Add image url to sorted list
Next
For Each Item in SortedList
'Add to checkbox list
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.