Coding

VBScript to list file owner and other attributes

Occasionally I need to look at the owner of a file or group of files. The below script helps me enumerate a folder and list the file attributes

'GetOwner.vbs

Set objShell = CreateObject ("Shell.Application")
Set objFolder = objShell.Namespace ("D:toolsAD")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim arrHeaders(13)
For i = 0 to 13
    arrHeaders(i) = objFolder.GetDetailsOf (objFolder.Items, i)
Next
For Each strFileName in objFolder.Items
    For i = 0 to 13
        If i <> 9 then
            Wscript.echo arrHeaders(i)     & ": " & objFolder.GetDetailsOf (strFileName, i)
        End If
    Next
    Wscript.Echo
Next

2 thoughts on “VBScript to list file owner and other attributes

  • Anonymous

    This modification is a re-usable subroutine that let's you pick what attributes you want included, and places the result in a tab-separated format, suitable for adding to a routine that writes the lines to a file.

    Dim strfolder
    ' Doesn't care if UNC has terminating backslash or not
    strFolder = "\MYSERVERTest_Data"
    GetFileAttributes(strFolder)

    Private Sub GetFileAttributes (StrFolder)
    Dim objShell, objFolder, objFSO, strFileName, strDisplayText, i
    Set objShell = CreateObject ("Shell.Application")
    Set objFolder = objShell.Namespace (strFolder)
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Dim arrHeaders(13)
    For i = 0 to 13
    arrHeaders(i) = objFolder.GetDetailsOf (objFolder.Items, i)
    Next
    For Each strFileName in objFolder.Items
    strDisplayText = ""
    ' Comment out any attributes you don't want
    strDisplayText = arrHeaders(0) & ": " & objFolder.GetDetailsOf (strFileName, 0) 'File Name
    strDisplayText = strDisplayText & vbTab & arrHeaders(1) & ": " & objFolder.GetDetailsOf (strFileName, 1) 'File Size
    strDisplayText = strDisplayText & vbTab & arrHeaders(2) & ": " & objFolder.GetDetailsOf (strFileName, 2) 'Item Type
    strDisplayText = strDisplayText & vbTab & arrHeaders(3) & ": " & objFolder.GetDetailsOf (strFileName, 3) 'Date Modified
    strDisplayText = strDisplayText & vbTab & arrHeaders(4) & ": " & objFolder.GetDetailsOf (strFileName, 4) 'Date Created
    strDisplayText = strDisplayText & vbTab & arrHeaders(5) & ": " & objFolder.GetDetailsOf (strFileName, 5) 'Date Accessed
    strDisplayText = strDisplayText & vbTab & arrHeaders(6) & ": " & objFolder.GetDetailsOf (strFileName, 6) 'Attributes
    strDisplayText = strDisplayText & vbTab & arrHeaders(7) & ": " & objFolder.GetDetailsOf (strFileName, 7) 'Offline Status
    strDisplayText = strDisplayText & vbTab & arrHeaders(8) & ": " & objFolder.GetDetailsOf (strFileName, 8) 'Offline Availability
    strDisplayText = strDisplayText & vbTab & arrHeaders(9) & ": " & objFolder.GetDetailsOf (strFileName, 9) 'Perceived type
    strDisplayText = strDisplayText & vbTab & arrHeaders(10) & ": " & objFolder.GetDetailsOf (strFileName, 10) 'Owner
    strDisplayText = strDisplayText & vbTab & arrHeaders(11) & ": " & objFolder.GetDetailsOf (strFileName, 11) 'Kind
    strDisplayText = strDisplayText & vbTab & arrHeaders(12) & ": " & objFolder.GetDetailsOf (strFileName, 12) 'Date Taken
    strDisplayText = strDisplayText & vbTab & arrHeaders(13) & ": " & objFolder.GetDetailsOf (strFileName, 13) Contributing Artists
    Wscript.echo strDisplayText
    Next
    End Sub

Leave a Reply