I'm killing myself and dehydrating trying to get this array to sort.
I have an array containing directories generated by;
Dim Folders() As String = Directory.GetDirectories(RootPath)
I need them to be sorted so they appear like in windows explorer in win7 / vista. -- numerically and alphabetically by folder names.
The folder names contain both letters and numbers, sometimes letters only or numbers only.
The simple Array.Sort(Folders) results in
C:inetpubwwwroot
ootpath1
C:inetpubwwwroot
ootpath10
C:inetpubwwwroot
ootpath100
C:inetpubwwwroot
ootpath1004
C:inetpubwwwroot
ootpath101
C:inetpubwwwroot
ootpath11
C:inetpubwwwroot
ootpath12
C:inetpubwwwroot
ootpath2
C:inetpubwwwroot
ootpath3
C:inetpubwwwroot
ootpath4
C:inetpubwwwroot
ootpath5
C:inetpubwwwroot
ootpath6
C:inetpubwwwroot
ootpath7
C:inetpubwwwroot
ootpath8
C:inetpubwwwroot
ootpath87skjnd
C:inetpubwwwroot
ootpath89sdf93kmw3
C:inetpubwwwroot
ootpath9
C:inetpubwwwroot
ootpathad
C:inetpubwwwroot
ootpathin
C:inetpubwwwroot
ootpathdark
C:inetpubwwwroot
ootpatherk
C:inetpubwwwroot
ootpathjkh23978yoaslkd3
C:inetpubwwwroot
ootpathlk2309as
C:inetpubwwwroot
ootpathwork
C:inetpubwwwroot
ootpathzone
What I want to have (and what windows explorer displays) is ...
C:inetpubwwwroot
ootpath1
C:inetpubwwwroot
ootpath2
C:inetpubwwwroot
ootpath3
C:inetpubwwwroot
ootpath4
C:inetpubwwwroot
ootpath5
C:inetpubwwwroot
ootpath6
C:inetpubwwwroot
ootpath7
C:inetpubwwwroot
ootpath8
C:inetpubwwwroot
ootpath9
C:inetpubwwwroot
ootpath10
C:inetpubwwwroot
ootpath11
C:inetpubwwwroot
ootpath12
C:inetpubwwwroot
ootpath87skjnd
C:inetpubwwwroot
ootpath89sdf93kmw3
C:inetpubwwwroot
ootpath100
C:inetpubwwwroot
ootpath101
C:inetpubwwwroot
ootpath1004
C:inetpubwwwroot
ootpathad
C:inetpubwwwroot
ootpathin
C:inetpubwwwroot
ootpathdark
C:inetpubwwwroot
ootpatherk
C:inetpubwwwroot
ootpathjkh23978yoaslkd3
C:inetpubwwwroot
ootpathlk2309as
C:inetpubwwwroot
ootpathwork
C:inetpubwwwroot
ootpathzone
I googled and found out that a class needs to be written that uses IComparable to sort the elements. Being a supernewbie ... I really don't know how it can be done. Most examples I looked at had multi dimensional arrays and keys :S ...
would be even nicer if the sorting could be applied to an array of filenames (instead of foldernames) or an array containing both folders and files ... in which case the sorted folders appear at the top and sorted files below ... is this even possible?
Any help will be greatly appriciated ... :D thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…