2011-09-30 8 views
1

이 디렉토리의 파일을 영숫자로 정렬하려면 어떻게합니까? 파일의 예 : 12325_2011.jpgVB.NET 알파벳순으로 디렉토리의 파일 정렬

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 

답변

4

그냥 수정하여이 같은 각 루프의 경우 기존 :

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

당신이 (내가) i.Name가 무엇인지 기능 설명 할 수 있을까요? – Bruno

+0

람다 표현식입니다. 정렬 기능을 사용하여 배열의 항목을 비교하는 방법을 OrderBy 함수에 알려주는 이름없는 작은 미니 함수입니다. –

+0

이것은 'creationtime'또는 다른 모든 속성에도 적용됩니다. – Markive

관련 문제