WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Files and Directories

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get & Set Summary File Properties


Question:

I would like to retrieve a files Summary properties, such as title, owner, subject Is this possible with WinBatch ?

Answer:

I think I may have found a way to do it in WinBatch....

This works on a single file:

#DefineFunction FileSummary (File,Request)
   ;0  Name
   ;1  Size
   ;2  Type
   ;3  Date Modified
   ;4  Date Created
   ;5  Date Accessed
   ;6  Attributes
   ;7  Status
   ;8  Owner
   ;9  Author
   ;10    Title
   ;11    Subject
   ;12    Category
   ;13    Pages
   ;14    Comments
   ;15    Copyright
   ;16    Artist
   ;17    Album Title
   ;18    Year
   ;19    Track Number
   ;20    Genre
   ;21    Duration
   ;22    Bit Rate
   ;23    Protected
   ;24    Camera Model
   ;25    Date Picture Taken
   ;26    Dimensions
   ;27    Not used
   ;28    Not used
   ;29    Not used
   ;30    Company
   ;31    Description
   ;32    File Version
   ;33    Product Name
   ;34    Product Version
   File = FileFullname( File )
   If !FileExist(File)
       Pause( "FileSummary Error", "Unable to locate specified file: " : file)
       Return 0
   EndIf
   strFileName = FileBaseName(File)
   strPathName = FilePath(File)
   objShell = CreateObject("Shell.Application")
   objFolder = objShell.Namespace(strPathName)
   detail = objFolder.GetDetailsOf(objFolder.ParseName(strFileName), request)
   objShell = 0
   Return Detail
#EndFunction

File='c:\Temp\test.exe'
Details = FileSummary (File,10) ;Get Title
If details !=0 Then Message ("Title",Details)

File='C:\Remember Me.wma'
Details = FileSummary (File,19) ;Track Number
If details !=0 Then Message ("Track Number",Details)

File='C:\Temp\100-0092_IMG.JPG'
Details = FileSummary (File, 24) ;Camera Model
If details !=0 Then Message ("Camera Model",Details)
Exit

This works on all files in a specific directory:

objShell = CreateObject ("Shell.Application")
objFolder = objShell.Namespace ("C:\temp")
arrHeaders = ArrDimension(14)
For i = 0 To 13
    arrHeaders[i] = objFolder.GetDetailsOf (objFolder.Items, i)
Next
ForEach strFileName In objFolder.Items
   data = ""
    For i = 0 To 13
       data =  data : arrHeaders[i]: ": " :objFolder.GetDetailsOf (strFileName, i): @LF
    Next
    Pause( strfilename.name, data)
Next
objShell = 0
objFolder = 0
Exit


Question:

I would also like to Set Summary File Properties. Can this be accomplished using the same technique?

Answer:

Sorry no. Unfortunately there is no method to 'SetDetailsOf'. In order to set the filesummary values you will need to install the DSOFILE component. The DSOFILE component lets you retrieve and edit office document properties from Winbatch.

Dsofile.exe is a self-extracting executable that provides a simple in-process ActiveX component for programmers to use in order to read and modify the Document Summary Properties for an OLE Structured Storage file such as native Excel, PowerPoint, Microsoft Visio, and Word documents. The component can also work on non-OLE documents when it is run on Windows 2000 with an NTFS file system.

You will need to install the DSOFILE.DLL file and register it before using it in your WinBatch script.

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q224/3/51.asp

First, download and run the DSOFILE component. This is a self-extracting ZIP file that contains a copy of DSOFILE.DLL. Second, place a copy of the DLL in your Windows System32 subdirectory, then execute:

To register the component use:

; The OLE Document Property Reader COM module.
DirChange(DirWindows(1))
sOLEDLL = "DSOFILE.DLL" 

; Register the COM component.
iResult = DllCall(sOLEDLL,long:"DllRegisterServer")
If iResult Then Exit ; Terminate immediately.
To unregister the component use:

; The OLE Document Property Reader COM module.
DirChange(DirWindows(1))
sOLEDLL = "DSOFILE.DLL" 

; Unregister the COM component.
iResult = DllCall(sOLEDLL,long:"DllUnregisterServer")
Now that you have the Document Summary Properties component installed you can now begin accessing the document summary properties.

Here is an example that works with Word:

;////////////////////////////////////////////////////////////////////////
; Winbatch - display select property information for Word Document
; Deana Falk. - 06/07/2006
; This code requires WinBatch 2004B or newer
;////////////////////////////////////////////////////////////////////////

file = "C:\Temp\WordTemp.doc"
If !FileExist(file) Then Exit

oDocProps = ObjectCreate("DSOFile.OleDocumentProperties")

; When the Open method is called, the OleDocumentProperties object that is named Dsofile tries to open the document for both 
; read access and write access. If the file has been marked read-only or if the files is located on an NTFS share that only 
; provides Read access, the call may fail. You may receive the following error message: Error 70: Permission denied
; If you want to open the file for read access only , pass True for the ReadOnly parameter on the Open method. Additionally, 
; you can pass the dsoOptionOpenReadOnlyIfNoWriteAccess (shortend to dsoReadOnlyNoWriteAccess) flag if you want Dsofile to try to open the file for editing. However, 
; if Dsofile cannot gain access because file is read-only or is locked by another process, open a read-only copy. Then, you can 
; verify whether the document is opened read-only by using the IsReadOnly property.
ReadOnly = @true
dsoReadOnlyNoWriteAccess = 2
oDocProps.Open(file,ReadOnly,dsoReadOnlyNoWriteAccess)

oSummaryProps = oDocProps.SummaryProperties

txt = ""
txt = StrCat(txt,"Caption: ",oSummaryProps.ApplicationName,@CRLF)
txt = StrCat(txt,"Title: ",oSummaryProps.Title,@CRLF)
txt = StrCat(txt,"Author: ",oSummaryProps.Author,@CRLF)
txt = StrCat(txt,"Word Count: ",oSummaryProps.WordCount,@CRLF)
txt = StrCat(txt,"Page Count: ",oSummaryProps.PageCount,@CRLF)   
txt = StrCat(txt,"Version: ",oSummaryProps.Version,@CRLF)
txt = StrCat(txt,"Revision Number: ",oSummaryProps.RevisionNumber,@CRLF)
txt = StrCat(txt,"Date Last Saved: ",oSummaryProps.DateLastSaved,@CRLF)
Message("Properties for %file%",txt)

ObjectClose(oSummaryProps)
ObjectClose(oDocProps)
exit

Note: Sadly, DOSFile supports only "Structured OLE documents." In plain English, this means that it is worthless against the new "x" documents (DOCX for Word 2007/2010, XLSX for Excel 2007/2010, PPTX for PowerPoint 2007/2010) etc.

Reference: http://msdn.microsoft.com/library/en-us/dnoffdev/html/vsofficedev.asp?frame=true#vsofficedev_topic20


Article ID:   W17283
File Created: 2010:12:01:10:26:58
Last Updated: 2010:12:01:10:26:58