Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

FileSystemObject tri par date

2 réponses
Avatar
Lolo
Bonjour za toutes zé à tous,

J'utilise quelques lignes de code pour parcourir une collection de fichiers.
du type :
<<
Dim FSO As New FileSystemObject

Dim Mon_Fichier As File
Dim Mon_Repertoire As Object
Dim Ma_Collection_Fichier As Object

Chargement = True

Me.L_Liste_Fichiers.Clear
Me.L_Liste_Fichiers = ""

Set Mon_Repertoire = FSO.GetFolder(Chemin_Piece_Jointe)
Set Ma_Collection_Fichier = Mon_Repertoire.Files

' Sélection de Word par défaut
Me.O_Word.Value = True

For Each Mon_Fichier In Ma_Collection_Fichier
If Mon_Fichier.Type = "Microsoft Word Document" Then
Me.L_Liste_Fichiers.AddItem Mon_Fichier.Name
End If
Next

Set Mon_Fichier = Nothing
Set FSO = Nothing
>>
Y a t il un moyen de realiser un tri par date pour faire
apparaitre par exemple les documents les plus récents en sommet de liste.

Merci.

2 réponses

Avatar
JB
Bonjour,

Private Sub UserForm_Initialize()
repertoire = "C:mesdoc"
Set fso = CreateObject("Scripting.fileSystemObject")
Set fold = fso.getFolder(repertoire)
n = fold.Files.Count
Dim temp()
ReDim temp(1 To n, 1 To 2)
i = 0
For Each file In fold.Files
i = i + 1
temp(i, 1) = LCase(file.Name)
temp(i, 2) = file.dateLastModified
Next
'---tri dates < ' si n important, remplacer par Quick-Sort
For i = 1 To n
For j = i + 1 To n
If temp(i, 2) < temp(j, 2) Then
tmp = temp(i, 2): temp(i, 2) = temp(j, 2): temp(j, 2) = tmp
tmp = temp(i, 1): temp(i, 1) = temp(j, 1): temp(j, 1) = tmp
End If
Next
Next i
'--
Me.ListBox1.List = temp
End Sub

JB
http://boisgontierjacques.free.fr

On 20 nov, 08:15, Lolo wrote:
Bonjour za toutes zé à tous,

J'utilise quelques lignes de code pour parcourir une collection de fichier s.
du type :
<<
Dim FSO As New FileSystemObject

Dim Mon_Fichier As File
Dim Mon_Repertoire As Object
Dim Ma_Collection_Fichier As Object

Chargement = True

Me.L_Liste_Fichiers.Clear
Me.L_Liste_Fichiers = ""

Set Mon_Repertoire = FSO.GetFolder(Chemin_Piece_Jointe)
Set Ma_Collection_Fichier = Mon_Repertoire.Files

' Sélection de Word par défaut
Me.O_Word.Value = True

For Each Mon_Fichier In Ma_Collection_Fichier
If Mon_Fichier.Type = "Microsoft Word Document" Then
Me.L_Liste_Fichiers.AddItem Mon_Fichier.Name
End If
Next

Set Mon_Fichier = Nothing
Set FSO = Nothing

Y a t il un moyen de realiser un tri par date pour faire
apparaitre par exemple les documents les plus récents en sommet de liste .

Merci.


Avatar
Lolo
Bonjour et merci de ta réponse.

Mais si il faut parcourir tous les fichiers,
stocker les nom et les date de création/modification dans un tableau,
puis faire un tri bulle, Quick-Sort ou autre je doit pouvoir me débrouiller,
je pensais que dans la bibliothèque FileSystemObject il y avait la
possibilité de faire cette action de tri sur une collection.


Bonjour,

Private Sub UserForm_Initialize()
repertoire = "C:mesdoc"
Set fso = CreateObject("Scripting.fileSystemObject")
Set fold = fso.getFolder(repertoire)
n = fold.Files.Count
Dim temp()
ReDim temp(1 To n, 1 To 2)
i = 0
For Each file In fold.Files
i = i + 1
temp(i, 1) = LCase(file.Name)
temp(i, 2) = file.dateLastModified
Next
'---tri dates < ' si n important, remplacer par Quick-Sort
For i = 1 To n
For j = i + 1 To n
If temp(i, 2) < temp(j, 2) Then
tmp = temp(i, 2): temp(i, 2) = temp(j, 2): temp(j, 2) = tmp
tmp = temp(i, 1): temp(i, 1) = temp(j, 1): temp(j, 1) = tmp
End If
Next
Next i
'--
Me.ListBox1.List = temp
End Sub

JB
http://boisgontierjacques.free.fr

On 20 nov, 08:15, Lolo wrote:
Bonjour za toutes zé à tous,

J'utilise quelques lignes de code pour parcourir une collection de fichiers.
du type :
<<
Dim FSO As New FileSystemObject

Dim Mon_Fichier As File
Dim Mon_Repertoire As Object
Dim Ma_Collection_Fichier As Object

Chargement = True

Me.L_Liste_Fichiers.Clear
Me.L_Liste_Fichiers = ""

Set Mon_Repertoire = FSO.GetFolder(Chemin_Piece_Jointe)
Set Ma_Collection_Fichier = Mon_Repertoire.Files

' Sélection de Word par défaut
Me.O_Word.Value = True

For Each Mon_Fichier In Ma_Collection_Fichier
If Mon_Fichier.Type = "Microsoft Word Document" Then
Me.L_Liste_Fichiers.AddItem Mon_Fichier.Name
End If
Next

Set Mon_Fichier = Nothing
Set FSO = Nothing

Y a t il un moyen de realiser un tri par date pour faire
apparaitre par exemple les documents les plus récents en sommet de liste..

Merci.