Set oFolderItem = oFolder.ParseName(sFileName) Set oFolder = oShell.NameSpace(CStr(sFilePath)) If (Not oFolder Is Nothing) Then
Set oShell = CreateObject("Shell.Application") SFileName = Right(sFile, Len(sFile) - InStrRev(sFile, "\")) Set oDic = CreateObject("Scripting.Dictionary") Optional sSortDir As String = "Asc") As Objectĭim vPropValue As Variant sFilePath = Left(sFile, InStrRev(sFile, "\") - 1)
' Added Sorting via the use of a dictionary objectįunction GetFileProperties(ByVal sFile As String, _ ' sSortDir : The order of the properties to sort on -> Asc/Desc ' sFile : Fully qualified path and filename of the file to get the properties of ' Req'd Refs: Late Binding -> none required ' Copyright : The following is release as Attribution-ShareAlike 4.0 International ' Purpose : Generate a Scripting Dictionary object of all the file properties ' Author : Daniel Pineault, CARDA Consultants Inc. , vbOKOnly + vbCritical, "An Error has Occured!" Resume Error_Handler_Exit Switch(Erl = 0, "", Erl 0, vbCrLf & "Line No: " & Erl) _ "Error Description: " & Err.Description & _ "Error Source: GetFileProperties" & vbCrLf & _ "Error Number: " & Err.Number & vbCrLf & _ MsgBox "The following error has occured" & vbCrLf & vbCrLf & _ On Error Resume Next If Not oFolderItem Is Nothing Then Set oFolderItem = Nothing If Not oFolder Is Nothing Then Set oFolder = Nothing If Not oShell Is Nothing Then Set oShell = Nothing If Not oDic Is Nothing Then Set oDic = Nothing Exit Function ODic.Add oFolder.GetDetailsOf(oFolder.Items, i), vPropValueĮnd If Next End If 'Sort the dictionary entries asc If sSortDir = "Asc" Then Set oDic = SortDictionaryByKey(oDic, "xlAscending")Įlse Set oDic = SortDictionaryByKey(oDic, "xlDescending") If Trim(vPropValue & vbNullString) "" Then VPropValue = oFolder.GetDetailsOf(oFolderItem, i) If ( Not oFolder Is Nothing) Then Set oFolderItem = oFolder.ParseName(sFileName)įor i = 0 To 320 'This could be bumped up in case MS increase the number again Set oFolder = oShell.NameSpace(CStr(sFilePath)) Set oShell = CreateObject( "Shell.Application") Set oDic = CreateObject( "Scripting.Dictionary") SFileName = Right(sFile, Len(sFile) - InStrRev(sFile, "\")) SFilePath = Left(sFile, InStrRev(sFile, "\") - 1) Optional sSortDir As String = "Asc") As Object On Error GoTo Error_Handlerĭim oDic As Object 'Scripting.Dictionary Dim oShell As Object 'Shell Dim oFolder As Object 'Folder Dim oFolderItem As Object 'FolderItem Dim sFilePath As String Dim sFileName As String Dim i As Long Dim vPropValue As Variant ' Website : ' Purpose : Generate a Scripting Dictionary object of all the file properties ' Copyright : The following is release as Attribution-ShareAlike 4.0 International ' (CC BY-SA 4.0) - ' Req'd Refs: Late Binding -> none required ' Dependencies : SortDictionaryByKey() ' ' ' Input Variables: ' ~~~~~~~~~~~~~~~~ ' sFile : Fully qualified path and filename of the file to get the properties of ' sSortDir : The order of the properties to sort on -> Asc/Desc ' ' Usage: ' ~~~~~~ ' See Test_GetFileProperties() ' ' Revision History: ' Rev Date(yyyy-mm-dd) Description ' ************************************************************************************** ' 1 Initial Release ' 2 Initial Public Release ' Increased iteration limit to 320 ' Added Sorting via the use of a dictionary object '- Function GetFileProperties( ByVal sFile As String, _ '- ' Procedure : GetFileProperties ' Author : Daniel Pineault, CARDA Consultants Inc.