1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| Option Explicit
' declaration des variables
Dim fso, f, fc, i, f1, oFolder, oShell, counter, triok, strMessage, bon, datebasse, datehaute, fichierhaut, fichierbas, filespec
'dim strMessage
Dim t()
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.BrowseForFolder(&H0&, "Choisir un répertoire", &H1&,"C:\")
Set f = fso.GetFolder(oFolder.ParentFolder.ParseName(oFolder.Title).Path)
' gestion erreur si l utilisateur ne selectionne pas de dossier
If Err.number<>0 Then
msgbox "L'erreur [" &_
err.description & "] s'est produite"
On Error GoTo 0
Wscript.quit 1
End If
Set fc = f.Files
'compter le nombre de fichier dans le dossier
counter = 0
for each f1 in fc
counter = counter + 1
next
'creation du tableau a la taille necessaire
counter = counter - 1
redim t(counter , 1)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'remplir le tableau
i = 0
for each f1 in fc
t(i, 0)= f1.Name
t(i, 1)= Int(CDbl(f1.DateCreated))
i = i + 1
next
'facultatif'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' test pour lire le tableau
strMessage = ""
For i = 0 To counter
strMessage = strMessage & t(i, 0) & " " & t(i, 1) & vbLf
Next
MsgBox strMessage, vbExclamation
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'tri du tableau
counter = counter - 1
triok = False
While triok = False
For i = 0 To counter
If t(i, 1) > t(i + 1, 1) Then
'deplacement des dates
datehaute = t(i, 1)
datebasse = t(i + 1, 1)
t(i + 1, 1) = datehaute
t(i, 1) = datebasse
'deplacement des noms de fichier
fichierhaut = t(i, 0)
fichierbas = t(i + 1, 0)
t(i + 1, 0) = fichierhaut
t(i, 0) = fichierbas
End If
Next
' facultatif'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' test pour lire le tableau
counter = counter + 1
strMessage = ""
For i = 0 To counter
strMessage = strMessage & t(i, 0) & " " & t(i, 1) & vbLf
Next
MsgBox strMessage, vbCritical
counter = counter - 1
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'verification du tri de mon tableau
bon = 0
For i = 0 To counter
If t(i, 1) < t(i + 1, 0) or t(i, 1) = t(i + 1, 0) Then
bon = bon + 1
End If
Next
If bon = counter + 1 Then
triok = True
End If
Wend |
Partager