Skip to content

Instantly share code, notes, and snippets.

@Linda-chan
Created December 9, 2019 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Linda-chan/08e364e8f420cd2ad5c055ae5b6032d5 to your computer and use it in GitHub Desktop.
Save Linda-chan/08e364e8f420cd2ad5c055ae5b6032d5 to your computer and use it in GitHub Desktop.
' https://stackoverflow.com/questions/34514580/get-document-properties-using-vbs
' https://stackoverflow.com/questions/5651890/using-vba-to-get-extended-file-attributes
Option Explicit
Dim FSO
Dim Shell
Call Main()
'====================================================================
Public Sub Main()
Dim FolderFSO
Dim Folder
Set Shell = CreateObject("Shell.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FolderFSO = FSO.GetFolder(".")
Set Folder = Shell.Namespace(FolderFSO.Path)
PropertyNamesTest Folder
'SingleItemTest Folder, "wxDKA5YwOJA.jpg"
'SingleItemTest Folder, "Descript.ion"
'MultiItemTest Folder
MultiItemTestFSO Folder, FolderFSO
End Sub
'====================================================================
Private Sub PropertyNamesTest(ByRef Folder)
Dim TMP
Dim TXT
For TMP = -1 To 1000
If IsNoProperty(Folder, Folder.Items, TMP, TXT) Then
WScript.Echo ""
Exit For
Else
WScript.Echo TMP & " ==> " & TXT
End If
Next
End Sub
'====================================================================
Private Sub SingleItemTest(ByRef Folder, ByVal FileName)
Dim File
Set File = Folder.ParseName(FileName)
SingleItemTest Folder, File
End Sub
'====================================================================
Private Sub SingleItemTest2(ByRef Folder, ByRef File)
Dim TXT1
Dim TXT2
Dim TMP
TMP = -2
Do
If Not IsNoProperty(Folder, Folder.Items, TMP, TXT1) Or _
Not IsNoProperty(Folder, File, TMP, TXT2) Then
If TXT2 <> "" Then _
WScript.Echo TMP & " :: " & TXT1 & " :: " & TXT2
Else
Exit Do
End If
TMP = TMP + 1
Loop
End Sub
'====================================================================
Private Sub MultiItemTest(ByRef Folder)
Dim File
For Each File In Folder.Items
WScript.Echo "### " & File
WScript.Echo ""
SingleItemTest2 Folder, File
WScript.Echo ""
Next
End Sub
'====================================================================
Private Sub MultiItemTestFSO(ByRef Folder, ByRef FolderFSO)
Dim FileFSO
Dim File
Dim Collection
For Each Collection In Array(FolderFSO.SubFolders, FolderFSO.Files)
For Each FileFSO In Collection
WScript.Echo "### " & FileFSO.Name
WScript.Echo ""
Set File = Folder.ParseName(FileFSO.Name)
SingleItemTest2 Folder, File
WScript.Echo ""
Next
Next
End Sub
'====================================================================
' GetDetailsOf
' ------------
'
' An Integer value that specifies the information to be retrieved.
' The information available for an item depends on the folder in
' which it is displayed. This value corresponds to the zero-based
' column number that is displayed in a Shell view. For an item in
' the file system, this can be one of the following values:
'
' (0) Retrieves the name of the item.
' (1) Retrieves the size of the item.
' (2) Retrieves the type of the item.
' (3) Retrieves the date and time that the item was last modified.
' (4) Retrieves the attributes of the item.
' (-1) Retrieves the info tip information for the item.
'
' https://docs.microsoft.com/en-us/windows/win32/shell/folder-getdetailsof
'====================================================================
Private Function IsNoProperty(ByRef FolderObject, _
ByRef ItemToCheck, _
ByVal PropertyIndex, _
ByRef lpActualValue)
Dim TXT
IsNoProperty = True
TXT = FolderObject.GetDetailsOf(ItemToCheck, PropertyIndex)
If TXT = "" Then
TXT = FolderObject.GetDetailsOf(ItemToCheck, PropertyIndex + 1)
If TXT = "" Then
TXT = FolderObject.GetDetailsOf(ItemToCheck, PropertyIndex + 2)
If TXT = "" Then
TXT = FolderObject.GetDetailsOf(ItemToCheck, PropertyIndex + 3)
If TXT = "" Then
TXT = FolderObject.GetDetailsOf(ItemToCheck, PropertyIndex + 4)
If TXT = "" Then
TXT = FolderObject.GetDetailsOf(ItemToCheck, PropertyIndex + 5)
If TXT = "" Then
TXT = FolderObject.GetDetailsOf(ItemToCheck, PropertyIndex + 6)
If TXT = "" Then
lpActualValue = ""
Exit Function
End If
End If
End If
End If
End If
End If
End If
lpActualValue = FolderObject.GetDetailsOf(ItemToCheck, PropertyIndex)
IsNoProperty = False
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment