'Ce script (VBS) a pour but d'afficher, dans une MsgBox, la liste des fichiers
'd'un répertoire, triés par date de modification (du + récent au + ancien)
'
'Translation de VB6 en VBS du code (réponse) proposé par "michelxld" (forum VBFrance)
'http://www.vbfrance.com/infomsg/OUVERTURE-FICHIER-RECENT-2_720974.aspx (le 22/04/2006 06:19:25)
'Un grand MERCI à "rvblog" sans lequel ce script ne serait pas fonctionnel !!!"
Option Explicit
Const Path = "d:\test"
MsgBox ShowFolderList(Path),,"Liste des fichiers du répertoire """ & Path &vbCrLf&_
""" triés par date de modification (du + récent au + ancien)"
Function ShowFolderList(strPath)
Dim fso, Dossiers, fic, fichiers, strListe, f, r
Dim Valeur, imax, z, Cible, liste
Set fso = CreateObject("Scripting.FileSystemObject")
Set Dossiers = fso.GetFolder(Path)
Set fic = Dossiers.Files
imax = 0
For Each fichiers In fic
Set f = fso.GetFile(fichiers)
imax = imax + 1
ReDim Preserve Tableau(2, imax)
Tableau(1, imax) = f.Name
Tableau(2, imax) = f.DateLastModified
Valeur = 0
For imax = 1 To imax - 1
If CDate(Tableau(2, imax)) < CDate(Tableau(2, imax + 1)) Then
For z = 1 To 2
Cible = Tableau(z, imax)
Tableau(z, imax) = Tableau(z, imax + 1)
Tableau(z, imax + 1) = Cible
Next
Valeur = 1
End If
Next
Next
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Affichage du résultat des fichiers triés par date de modification
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
liste = ""
For r = 1 To imax
liste = liste & vbCrLf & r & " " & Tableau(2, r) & " " & Tableau(1, r)
Next
liste = vbCrLf& "N° Date de modification Nom du fichier" &vbCrLf& liste
ShowFolderList = liste
Set fso = Nothing
Set Dossiers = Nothing
Set fic = Nothing
Set f = Nothing
End Function