Using a script to get a folder listing with file details

A couple of days ago I got a request from a software vendor to make screenshots of the files in the system32 folder of a machine for which we had opened a support call. The support contact asked to enable the 'details' view in windows explorer, and add the 'file version' and product version' columns. A quick calculation told me that that would take over 100 screenshots. And even then, the support persoon would have to manually examine each of them as a picture.

In short and polite terms, that was a bad idea.

I know why she asked. The simple 'dir' command does not have the ability to display these details. However, since the information is available in Windows Explorer, it had to be available to VBScript as well. A modest amount of google-fu(1) gave me enough information to cobble together a quick script for putting the requested info in a csv file.

Option Explicit
Dim fso, fc, f, fs 
Dim strPath, strFile

'On Error Resume Next

strPath = "C:\files.txt"

Set fso = CreateObject("Scripting.FileSystemObject")
Set strFile = fso.CreateTextFile(strPath, True)
strFile.WriteLine("FileName,Last Modified,File Version,Product Version")

Set f = fso.GetFolder("C:\Windows\System32")         
Set fc = f.Files
For Each fs In fc

    strFile.WriteLine(fs.Name & "," & fs.DateLastModified & "," & fso.GetFileVersion(fs) & "," & GetProductVersion ("C:\Windows\System32", fs.Name) )

Next


Function GetProductVersion (sFilePath, sProgram)
Dim objShell, objFolder, objFolderItem, i 
If FSO.FileExists(sFilePath & "\" & sProgram) Then
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(sFilePath)
    Set objFolderItem = objFolder.ParseName(sProgram)
    Dim arrHeaders(300)
    For i = 0 To 300
        arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
        'WScript.Echo i &"- " & arrHeaders(i) & ": " & objFolder.GetDetailsOf(objFolderItem, i)
        If lcase(arrHeaders(i))= "product version" Then
            GetProductVersion= objFolder.GetDetailsOf(objFolderItem, i)
            Exit For
        End If
    Next
End If
End Function

 

  1. http://stackoverflow.com/questions/2976734/how-to-retrieve-a-files-product-version-in-vbscript