Public Sub GetFileExtProps(strFilePath As String)
strProc = "GetFileExtProps"
'This requires the reference: Microsoft Shell Controls and Automation
'Examples:
'GetFileExtProps "G:\Programs\MendipDataSystems\CommonFiles\SDA\Icons\SDA_DEMO.ico"
'GetFileExtProps "G:\Programs\MendipDataSystems\CommonFiles\SDA\Images\AccessErrorCodes.gif"
'GetFileExtProps "G:\Programs\MendipDataSystems\CommonFiles\SDA\Photos\000146.bmp"
'GetFileExtProps "G:\Programs\MendipDataSystems\CommonFiles\SDA\Documentation\AnalyseSessionReportGrades.pdf"
'GetFileExtProps "D:\Colin\My Documents\My Music\Leonard Cohen\You Want It Darker\04 Leaving The Table.mp3"
'GetFileExtProps "C:\Programs\MendipDataSystems\SDALink\Spreadsheets\SIMs_StudentAttendanceMarks_Yr09.csv"
'GetFileExtProps "C:\Programs\MendipDataSystems\SPS\SPS.accdb"
'GetFileExtProps "C:\Programs\MendipDataSystems\SDA\ExportImportTemplates\Template.xlsx"
On Error GoTo Err_Handler
'clear temp table - left out of v4 by mistake
CurrentDb.Execute "DELETE tblFileExtPropsTEMP.* FROM tblFileExtPropsTEMP;"
'get file details
I = 1
strFileName = strFilePath
Do Until I = 0 'find the last "\" and get the filename
I = InStr(1, strFileName, "\", vbBinaryCompare)
strFileName = Mid(strFileName, I + 1)
Loop
strPath = Left(strFilePath, Len(strFilePath) - Len(strFileName) - 1)
Set objShell = New Shell
Set objFolder = objShell.NameSpace(strPath)
Set objFolderItem = objFolder.ParseName(strFileName)
N = 0
'get extended properties & values and save to table tblFileExtPropsTEMP
For I = 0 To 310
aName = objFolder.GetDetailsOf(objFolder.Items, I)
aValue = objFolder.GetDetailsOf(objFolderItem, I)
'full list of available extended properties (depending on file type)
'Debug.Print I & " - " & objFolder.GetDetailsOf(objFolder.Items, I)
'list extended properties available in this folder:
If Nz(aName, "") <> "" And Nz(aValue, "") <> "" Then
' Debug.Print I & " - " & aName & ": " & aValue
'append query fails if any [COLOR="DarkRed"]aValue[/COLOR] contains a '; replace with a |
[COLOR="darkred"] If InStr(aValue, "'") > 0 Then
aValue = Replace(aValue, "'", "|")[/COLOR]
N = N + 1
End If
' Debug.Print aName, aValue, N
'remove any '?' in extended property value
aValue = Replace(aValue, "?", "")
'append record to tblExtPropsFileType
strSQL = "INSERT INTO tblFileExtPropsTEMP ( ID, ExtProperty, ExtPropValue )" & _
" SELECT " & I & " AS ID, '" & aName & "' AS ExtProperty, '" & aValue & "' AS ExtPropValue ;"
CurrentDb.Execute strSQL
End If
Next I
'now restore any ' replaced earlier with a |
If N > 0 Then
strSQL = "UPDATE tblFileExtPropsTEMP SET tblFileExtPropsTEMP.ExtPropValue = Replace([ExtPropValue][COLOR="darkred"],'|','''');"[/COLOR][COLOR="SeaGreen"] 'note this is 4 apostrophes NOT two double quotes[/COLOR]
CurrentDb.Execute strSQL
End If
Set objFolderItem = Nothing
Set objFolder = Nothing
Set objShell = Nothing
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " in " & strProc & " procedure: " & Err.Description
Resume Exit_Handler
End Sub