* File attributes #DEFINE FILE_ATTRIBUTE_ARCHIVE 32 #DEFINE FILE_ATTRIBUTE_COMPRESSED 2048 #DEFINE FILE_ATTRIBUTE_DIRECTORY 16 #DEFINE FILE_ATTRIBUTE_HIDDEN 2 #DEFINE FILE_ATTRIBUTE_NORMAL 128 #DEFINE FILE_ATTRIBUTE_READONLY 1 #DEFINE FILE_ATTRIBUTE_SYSTEM 4 #DEFINE FILE_ATTRIBUTE_TEMPORARY 256Then I have a function called 'FileAttributes()' as follows:
Function FileAttributes LParameters tcFile, tnAttribute, tlSet * declares for file attribute functions Declare Integer GetFileAttributes in kernel32 string filename Declare Integer SetFileAttributes in kernel32 string filename, integer fileattributes Local llOk, lnCurrent llOk = .F. If PCount() = 3 llOk = .T. Endif IF llOk AND File(tcFile) lnCurrent = GetFileAttributes(tcFile) If !(lnCurrent = -1 or lnCurrent > 2487) && -1 is error condition, 2487 is max && otherwise we have a problem * check for setting of requested attribute IF BitAnd(lnCurrent, tnAttribute) = tnAttribute && the attribute is already set If !tlSet && wants attribute unset, do it, otherwise, do nothing llOk = (SetFileAttributes(tcFile, lnCurrent - tnAttribute) = 1) && 1 means ok else llOk = .T. Endif Else && not currently set If tlSet && want it set, set it, otherwise do nothing llOk = (SetFileAttributes(tcFile, lnCurrent + tnAttribute) = 1) Else llOk = .T. Endif endif Endif Endif Return llOkThen if you want to set the read-only attribute, call it like so:
FileAttributes(<filename>, FILE_ATTRIBUTE_READONLY, .T.)To be perfectly honest, I cannot recall now, whether I wrote this function, or stole it from someone else.