Sub Test_Cmd_DIR()
Dim Liste, tim
[a1].EntireColumn.ClearContents
tim = Timer
Liste = CmdDirList("k:\vba excel\", "*cdo*", "*.xl*", True) '(1252 ou omis = normal / 65001 utf-8)
tim = Format(Timer - tim, "#,##0.##\ sec.")
[a1].Resize(UBound(Liste)) = Application.Transpose(Liste)
MsgBox tim
End Sub
Function CmdDirList(lFolder$, _
Optional Expression As String = "*", _
Optional Extension As String = "*.*", _
Optional Recursif As Boolean = False, _
Optional TextFormat As Long = 1252)
'CmdDirList V 2.7(StdOut.ReadAll)
'@patricktoulon
'@jurassic pork
'@mapomme
Dim sn, res$, CHCP&, TempString$, recurr$
If Right(lFolder, 1) <> "\" Then lFolder = lFolder & "\"
If Recursif Then recurr = " /S" ' récursivité
TempString = "& cmd /C dir """ & lFolder & Expression & Extension & Chr(34) & recurr & " /a:-d /b "
Debug.Print TempString
res = CreateObject("wscript.shell").exec("cmd /c chcp " & TextFormat & " > nul " & TempString).StdOut.ReadAll
If res <> "" Then
CmdDirList = Split(res, vbCrLf)
Else: res = Array("")
End If
End Function