Reply to comment

Retrieving Extended File Properties

When you right-click a file in Windows Explorer and select Properties from the shortcut menu, a dialog box displays basic properties for that file, including such things as file name, file size, and the file creation, last access, and last modification dates. In addition to these basic properties, the Windows operating system also tracks a number of extended file properties. These properties are typically hidden; to display them in Windows Explorer, you must click View, click Choose Details, and then select the desired properties from the resulting dialog box.

The Shell Folder object includes a GetDetailsOf method that allows to access these extended properties. A ParseName method can be used to retrieve a FolderItem object that represents a specified item.

This is sample code. Add error handling and adjust to your requirements as necessary.

CLEAR
 
#DEFINE ccPropName  1
#DEFINE ccPropIndex 2
#DEFINE ccPropValue 3
lcCRLF = CHR(13) + CHR(10)
 
loShell = CREATEOBJECT("Shell.Application")
 
DIMENSION laFileProperties[1,3]
lnPropCount = 0
 
lcFolderName = "C:\Windows"
loFolder = loShell.Namespace(lcFolderName)
 
* Enumerate available properties by passing Null as the first parameter to the GetDetailsOf() method
FOR i = 0 TO 99
	lcPropName = loFolder.GetDetailsOf(Null, i)
 
	IF EMPTY(lcPropName)
		* Ignore empty items. They're either reserved or not supported for the current folder.
		LOOP
	ENDIF	
 
	* One property 
	lnPropCount = lnPropCount + 1 
	DIMENSION laFileProperties[lnPropCount, ALEN(laFileProperties,2)]
	* Property name
	laFileProperties[lnPropCount,ccPropName] = lcPropName 
	* Property index for the GetDetailsOf() method
	laFileProperties[lnPropCount,ccPropIndex] = i
ENDFOR
 
* Special 'Info Tip' ptoperty with index -1
lnPropCount = lnPropCount + 1 
DIMENSION laFileProperties[lnPropCount, ALEN(laFileProperties,2)] 
laFileProperties[lnPropCount,ccPropName] = "Info Tip" 
laFileProperties[lnPropCount,ccPropIndex] = -1
 
*------------------------------------------------------------------------------------------------------
* Retrieve extended properties for a particular file and store its values in the same array (column 3)
*	and convert properties into cursor's fields through XmlToCursor()
lcFileName = "clock.avi"
loFolder = loShell.Namespace(lcFolderName)
* Get reference to the file 
loFile = loFolder.ParseName(lcFileName)
* Check if file exists and retreive property values
IF NOT ISNULL(loFile)
	lcXml = [<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?><VFPData>]
	lcXml = lcXml + lcCRLF + "<FileProperties>"
	FOR lnInd=1 TO lnPropCount 
		lvValue = loFolder.GetDetailsOf(loFile, laFileProperties[lnInd, ccPropIndex])
		laFileProperties[lnInd, ccPropValue] = lvValue 
		lcFieldName = CHRTRAN(laFileProperties[lnInd, ccPropName], SPACE(1), "")
		lcXml = lcXml + lcCRLF + TEXTMERGE("<{{lcFieldName}}>{{lvValue}}</{{lcFieldName}}> ",.F.,"{{", "}}" ) 
	ENDFOR
	lcXml = lcXml + lcCRLF + "</FileProperties>"
	lcXml = lcXml + "</VFPData>"
ENDIF
 
XMLTOCURSOR(lcXML, "crsFilePropertiesEx")
 
BROWSE LAST NOWAIT 
 
*------------------------------------------------------------------------------------------------------
* Retrieve extended properties for a list of files in the same folder
 
loFolder = loShell.Namespace(lcFolderName)
lcXml = [<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?><VFPData>]
 
FOR EACH loItem IN loFolder.Items 
 
	IF INLIST(UPPER(JUSTEXT(loItem.Name)), "AVI", "BMP")
		lcXml = lcXml + lcCRLF + "<FileProperties>"
		FOR lnInd=1 TO lnPropCount 
			lvValue = loFolder.GetDetailsOf(loItem, laFileProperties[lnInd, ccPropIndex])
			laFileProperties[lnInd, ccPropValue] = lvValue 
			lcFieldName = CHRTRAN(laFileProperties[lnInd, ccPropName], SPACE(1), "")
			lcXml = lcXml + lcCRLF + TEXTMERGE("<{{lcFieldName}}>{{lvValue}}</{{lcFieldName}}> ",.F.,"{{", "}}" ) 
		ENDFOR
		lcXml = lcXml + lcCRLF + "</FileProperties>"
	ENDIF	
ENDFOR
 
lcXml = lcXml + "</VFPData>"
 
XMLTOCURSOR(lcXML, "crsFilesPropertiesEx")
 
BROWSE LAST NOWAIT 
 
RETURN

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <java>, <powershell>, <tsql>, <visualfoxpro>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.