VB.NET 按字母数字对目录中的文件进行排序 [英] VB.NET Sort files in directory by alphanumeric

查看:41
本文介绍了VB.NET 按字母数字对目录中的文件进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何按字母数字对下面这个目录中的文件进行排序?文件示例:12325_2011.jpg

How do I sort the files in this directory below by alphanumeric? An example of a file: 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 循环:

Just modify your existing For Each loop like this:

For Each image In imageArray.OrderBy(Function(i) i.Name)
    CheckBoxList1.Items.Add(image.Name)
Next

这篇关于VB.NET 按字母数字对目录中的文件进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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