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
Recent comments
1 week 4 days ago
4 weeks 19 hours ago
4 weeks 23 hours ago
4 weeks 1 day ago
4 weeks 1 day ago
5 weeks 2 days ago
8 weeks 2 days ago
10 weeks 4 days ago
12 weeks 2 days ago
12 weeks 3 days ago