locked
Retrive a file keywords using script RRS feed

  • Question

  • I cant find out how to get a file keywords, i can get title, aurthor and everything else.

    I can rightclick the file and choose properties to enter new keywords but it would be great if it works by using script..

     

    Here is an example..

    Dim arrHeaders(35)
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace("C:\Scripts")
    For i = 0 to 34
     arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
    Next
    For Each strFileName in objFolder.Items
     For i = 1 to 34
     Wscript.Echo i & vbtab & arrHeaders(i) _
     & ": " & objFolder.GetDetailsOf(strFileName, i)
     Next
    Next

    Wednesday, February 1, 2012 9:32 AM

Answers

  • Hi

    Try below code it VIEW those properties,

    But before this you need to register "Dsofile.dll"

    You can get the dll from http://support.microsoft.com/?kbid=224351 Just download the package and install, after installation copy the dll file in System32 folder and register it using "regsvr32 C:\Windows\System32\Dsofile.dll".

    The installation is not mandatroy only u need to get the dll file from the pachage so after you got the dll file simply uninstall the package and register the dll.

    ---------------------------------------------------------------

    doc = "c:\myfile.txt"
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists (doc) Then
     Set objFile = CreateObject("DSOFile.OleDocumentProperties")
      
     objfile.open(doc)
     msgbox objfile.SummaryProperties.title
     msgbox objfile.SummaryProperties.subject
     msgbox objfile.SummaryProperties.category
     msgbox objfile.SummaryProperties.keywords
     msgbox objfile.SummaryProperties.comments
     
    else
     MsgBox "File does not exists",vbOKOnly,doc
    end if
    ----------------------------------------------------------

    To update feilds try this

    doc = "c:\myfile.txt"
    Set fso = CreateObject("Scripting.FileSystemObject")

    If fso.FileExists (doc) Then
     Set objFile = CreateObject("DSOFile.OleDocumentProperties")
     
     objfile.open(doc)
     
     objfile.SummaryProperties.title = "my title"
     objfile.SummaryProperties.subject = "my subject"
     objfile.SummaryProperties.category = "my category"
     objfile.SummaryProperties.keywords = "my keywords"
     objfile.SummaryProperties.comments = "my comments"
     

     objfile.save
    else
     MsgBox "File does not exists",vbOKOnly,doc
    end if
    ------------------------------------------------------

     

    Shantanu

    • Proposed as answer by Shan_Shan Thursday, February 2, 2012 10:03 AM
    • Unproposed as answer by Shan_Shan Thursday, February 2, 2012 10:03 AM
    • Proposed as answer by Shan_Shan Thursday, February 2, 2012 10:03 AM
    • Marked as answer by arnavsharmaModerator Wednesday, July 10, 2013 10:18 AM
    Thursday, February 2, 2012 10:01 AM