Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Function ListeFichier(strPath As String, Optional SortOrder As Integer = 0) As String()
Dim Fich As String
Dim Name As String
Dim T() As String
Dim D() As Date
Dim dt As Date
Dim X() As Long
Dim P As Long
Dim G As Long
Dim M As Long
Dim nb As Long
If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"
Fich = Dir(strPath & "*.*", vbHidden Or vbSystem)
Do Until Fich = ""
Name = strPath & Fich
dt = FileDateTime(Name)
P = 1: G = nb: M = 0
If nb > 0 Then
While P < G
M = (P + G) \ 2
If dt > D(X(M)) Then P = M + 1 Else G = M
Wend
If P > M Then
If dt > D(X(P)) Then P = P + 1
End If
Do While P <= nb
If dt < D(X(P)) Then Exit Do
If dt > D(X(P)) Then Exit Do
P = P + 1
Loop
End If
nb = nb + 1
ReDim Preserve T(nb), D(nb), X(nb)
If P < nb Then
CopyMemory X(P + 1), X(P), (nb - P) * 4
End If
X(P) = nb
T(nb) = Name
D(nb) = dt
Fich = Dir()
Loop
ReDim temp(nb) As String
If SortOrder Then
G = nb: M = -1
Else
G = 1: M = 1
End If
For P = 1 To nb
temp(P) = T(X(G))
G = G + M
Next
ListeFichier = temp
Erase T, temp, D, X
End Function