30-03-21, 04:23 AM
اخوي تفضل هذا الكود
اولا- اضف الكلاس التالي الى مشروعك
كود :
Public Class myComparer
Implements IComparer(Of String)
Public Function Compare(ByVal x As String, _
ByVal y As String) As Integer _
Implements IComparer(Of String).Compare
If x Is Nothing Then
If y Is Nothing Then
' If x is Nothing and y is Nothing, they're
' equal.
Return 0
Else
' If x is Nothing and y is not Nothing, y
' is greater.
Return -1
End If
Else
' If x is not Nothing...
'
If y Is Nothing Then
' ...and y is Nothing, x is greater.
Return 1
Else
' ...and y is not Nothing, compare the
' lengths of the two strings.
'
Dim retval As Integer = _
x.Length.CompareTo(y.Length)
If retval <> 0 Then
' If the strings are not of equal length,
' the longer string is greater.
'
Return retval
Else
' If the strings are of equal length,
' sort them with ordinary string comparison.
'
Return x.CompareTo(y)
End If
End If
End If
End Function
End Classثانيا- استبدل الكود الذي تستخدمه بالتالي
كود :
TextBox4.Text = ""
Dim PathGG As String = TextBox1.Text
Dim DirPathGG As Boolean = IO.Directory.EnumerateDirectories(PathGG).Any ' الحقق من وجود ملفات في مسار الماي يوزر
If DirPathGG Then
Dim MyFiles As New List(Of String)
MyFiles.AddRange(Directory.GetDirectories(PathGG, "*", SearchOption.TopDirectoryOnly))
Dim c As New myComparer
MyFiles.Sort(0, MyFiles.Count, c)
For Each strFile In MyFiles
TextBox4.Text = Path.GetFileName(strFile)
Next
End If


