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
| Sub ListOSTFiles(strFolderName)
' adapté de Ole P Erlandsen
' necessite d'activer la reference Microsoft Scripting RunTime
Static fso As Object
Dim oSourceFolder As Object
Dim oSubFolder As Object
Dim oFile As Object
Static wksDest As Worksheet
Static iRow As Long
Static bNotFirstTime As Boolean
If Not bNotFirstTime Then
Set wksDest = ThisWorkbook.Worksheets("OST")
Set fso = CreateObject("Scripting.FileSystemObject")
wksDest.Cells(1, 1) = "Parent folder"
wksDest.Cells(1, 2) = "Full path"
wksDest.Cells(1, 3) = "File name"
wksDest.Cells(1, 4) = "Size"
wksDest.Cells(1, 5) = "Type"
wksDest.Cells(1, 6) = "Date created"
wksDest.Cells(1, 7) = "Date last modified"
wksDest.Cells(1, 8) = "Date last accessed"
wksDest.Cells(1, 9) = "Attributes"
wksDest.Cells(1, 10) = "Short path"
wksDest.Cells(1, 11) = "Short name"
wksDest.Cells(1, 12) = "Date extraction"
iRow = wksDest.Range("a" & wksDest.Rows.Count).End(xlUp).Row + 1
bNotFirstTime = True
End If
On Error GoTo fin
Set oSourceFolder = fso.GetFolder(strFolderName)
For Each oFile In oSourceFolder.Files
If fso.GetExtensionName(oFile.Name) = "ost" Then
wksDest.Cells(iRow, 1) = oFile.ParentFolder.Path
wksDest.Cells(iRow, 2) = oFile.Path
wksDest.Cells(iRow, 3) = oFile.Name
wksDest.Cells(iRow, 4) = MEF_Octet_Short(oFile.Size)
wksDest.Cells(iRow, 5) = oFile.Type
wksDest.Cells(iRow, 6) = oFile.DateCreated
wksDest.Cells(iRow, 7) = oFile.DateLastModified
wksDest.Cells(iRow, 8) = oFile.DateLastAccessed
wksDest.Cells(iRow, 9) = oFile.Attributes
wksDest.Cells(iRow, 10) = oFile.ShortPath
wksDest.Cells(iRow, 11) = oFile.ShortName
wksDest.Cells(iRow, 12) = Now
wksDest.Hyperlinks.Add Anchor:=wksDest.Cells(iRow, 2), Address:= _
oFile.Path, _
TextToDisplay:= _
oFile.Path
iRow = iRow + 1
End If
Next oFile
fin:
End Sub |