Results 1 to 5 of 5

Thread: [twinBASIC] Dump all file properties/metadata visible to Explorer to text file

Threaded View

  1. #1

    Thread Starter
    Join Date
    Jul 2010

    [twinBASIC] Dump all file properties/metadata visible to Explorer to text file

    PropDumper v1.0

    This program will create a dump of all properties and metadata visible to Explorer which aren't blank for the given file.

    You can create these output files with the specified extension, in the same folder where the file resides or a central folder. If the output already exists, there's an option to rename to the next available name the same way Windows does, File (1).txt, File (2).txt, whatever number is available.

    Properties include hidden Unicode codepoints indicating whether it's left to right or right to left; I usually view text in Notepad with Western script instead of Unicode, so I find it useful to remove these. So that option is there.

    This will not go into zip/cab files, even though Windows considers them folders now.

    This is all done by using the Windows Property System (IPropertyStore et al), which is the system that underlies how all the properties are displayed in Explorer-- so you're able to list exactly what Explorer is, without having to worry about having to derive things like image width/height yourself. If Explorer can see it, it will be in the dump. Note: Some properties like Office are derived through 64bit shell extensions that won't load into 32bit apps; so if you want to make sure it's an identical representation, use the 64bit build for 64bit Windows.

    I made this project primarily to test things in my tbShellLib library, a collection of Windows shell interfaces and other COM components that's a 64bit compatible successor my oleexp.tlb project for VB6. Note that this is why the source code file is so large; it imports the entire library. Which is quite expansive.

    (Note that since this project uses new language features in tB, it would take some work to backport it to VB6).


    Windows 7+

    Source and binaries are self-contained, no installation or additional dependencies.

    Building from source requires twinBASIC Beta 147 or newer.

    Dumping properties

    Windows shell interfaces and Property System make dumping properties very easy:

    Private Sub DumpFileProperties(siFile As IShellItem, sName As String)
        Dim sOut As String
        Dim lpPath As LongPtr, sPath As String
        siFile.GetDisplayName SIGDN_FILESYSPATH, lpPath
        sPath = LPWSTRtoStr(lpPath)
        sOut = "Filename: " & sName & vbCrLf
        sOut &= "File full path: " & sPath & vbCrLf
        Dim si2 As IShellItem2
        Dim pps As IPropertyStore
        Dim ppd As IPropertyDescription
        Dim lpFmt As LongPtr, sPropFmt As String
        Dim sFileOut As String
        If bCurDir Then
            sFileOut = sPath & sExt
            sFileOut = sPathOut & sExt
        End If
        If PathFileExistsW(sFileOut) Then
            If chkRename.Value = vbChecked Then
                sFileOut = UniqueNameInSeq(sFileOut)
                AppendLog "Skipping " & sName & "; output file exists."
                Exit Sub
            End If
        End If
        Set si2 = siFile
        si2.GetPropertyStore GPS_DEFAULT Or GPS_BESTEFFORT Or GPS_OPENSLOWITEM, IID_IPropertyStore, pps
        If (pps Is Nothing) = False Then
            Dim nMax As Long
            pps.GetCount nMax
            If nMax Then
            	AppendLog "Dumping " & nMax & " properties for " & sName & "..."
                Dim i As Long
                Dim pk As PROPERTYKEY
                Dim lpProp As LongPtr, sProp As String
                Dim lpPropC As LongPtr, sPropC As String
                Dim lpPropN As LongPtr, sPropN As String
                For i = 0 To nMax - 1
                    pps.GetAt i, pk
                    If pk.fmtid.Data1 <> 0 Then
                        PSGetPropertyDescription pk, IID_IPropertyDescription, ppd
                        If (ppd Is Nothing) = False Then
                            ppd.GetDisplayName lpPropN
                            sPropN = LPWSTRtoStr(lpPropN)
                            ppd.GetCanonicalName lpPropC
                            sPropC = LPWSTRtoStr(lpPropC)
                            PSFormatPropertyValue ObjPtr(pps), ObjPtr(ppd), PDFF_DEFAULT, lpProp
                            sProp = LPWSTRtoStr(lpProp)
                            If bRemoveFmt Then RemoveFormatChars(sProp)
                            If sProp <> "" Then sOut &= sPropN & " (" & sPropC & ")=" & sProp & vbCrLf
                            Debug.Print "Couldn't get propdesc for " & dbg_PKEYToString(pk)
                        End If
                    End If
                Next i
                sOut &= "No properties listed for file."
            End If
            AppendLog "Couldn't open property store for " & sPath
            sOut &= "Couldn't open property store for this file."
        End If
        WriteStrToFile sOut, sFileOut
        nCount = nCount + 1
    End Sub
    This project is also on GitHub.
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width