* * Get/Set file attributes using WinAPI * * Modification History: * 12/15/98 FBT Original * * Calling Sequence: * Get attributes: * lcRetVal = attrib(lcFilePathName) * * Where: * lcFilepathName = complete file name * * Returns: "RHSDANT" or "-" for error * * Set attributes: * lcRetVal = attrib(lcFilePathName,lcAttributes) * * Where: * lcFilepathName = complete file name * lcAttributes = Contains: * "R" - Read Only * "H" - Hidden * "S" - System * "D" - Directory * "A" - Archive * "N" - Normal * "T" - Temporary * Returns: * 0 - error * 1 - success * FUNCTION attrib LPARAMETERS tcFile, tcSetAttribs #DEFINE FILE_ATTRIBUTE_READONLY 0x00000001 #DEFINE FILE_ATTRIBUTE_HIDDEN 0x00000002 #DEFINE FILE_ATTRIBUTE_SYSTEM 0x00000004 #DEFINE FILE_ATTRIBUTE_DIRECTORY 0x00000010 #DEFINE FILE_ATTRIBUTE_ARCHIVE 0x00000020 #DEFINE FILE_ATTRIBUTE_NORMAL 0x00000080 #DEFINE FILE_ATTRIBUTE_TEMPORARY 0x00000100 LOCAL lxRetVal, laAttribs[7,2], lcFile, xx laAttribs[1,1] = FILE_ATTRIBUTE_TEMPORARY laAttribs[1,2] = "T" laAttribs[2,1] = FILE_ATTRIBUTE_NORMAL laAttribs[2,2] = "N" laAttribs[3,1] = FILE_ATTRIBUTE_ARCHIVE laAttribs[3,2] = "A" laAttribs[4,1] = FILE_ATTRIBUTE_DIRECTORY laAttribs[4,2] = "D" laAttribs[5,1] = FILE_ATTRIBUTE_SYSTEM laAttribs[5,2] = "S" laAttribs[6,1] = FILE_ATTRIBUTE_HIDDEN laAttribs[6,2] = "H" laAttribs[7,1] = FILE_ATTRIBUTE_READONLY laAttribs[7,2] = "R" lcFile = tcFile + CHR(0) IF EMPTY(tcSetAttribs) OR TYPE('tcSetAttribs')<>'C' * * Get attributes * LOCAL lnFileAttrib DECLARE INTEGER GetFileAttributes IN Win32API STRING @cFile lnFileAttrib = GetFileAttributes(@tcFile) IF lnFileAttrib>0 lxRetVal = "" FOR xx=1 TO ALEN(laAttribs,1) IF BITAND(lnFileAttrib,laAttribs[xx,1])>0 lxRetVal = lxRetVal + laAttribs[xx,2] ENDIF ENDFOR ELSE lxRetVal = "-" ENDIF ELSE * * Set attributes - anything not specified is reset! * LOCAL lcAttribs, lnSet lcAttribs = UPPER(tcSetAttribs) DECLARE INTEGER SetFileAttributes IN Win32API STRING @cFile, INTEGER nAttribs lnSet = FILE_ATTRIBUTE_NORMAL && Replaced by other attributes FOR xx=1 TO ALEN(laAttribs,1) IF laAttribs[xx,2] $ lcAttribs lnSet = BITOR(lnSet,laAttribs[xx,1]) ENDIF ENDFOR lxRetVal = SetFileAttributes(@lcFile,lnSet) ENDIF RETURN lxRetVal