The following code should do the trick, it should be noted that some of the attribute declarations cannot be used with the SetFileAttributes API call.
FILE_ATTRIBUTE_DIRECTORY = CreateDirectory()/CreateDirectoryEx()
FILE_ATTRIBUTE_ENCRYPTED = Use through CreateFile()/EncryptFile()
FILE_ATTRIBUTE_SPARSE_FILE = DeviceIoControl()
FILE_ATTRIBUTE_REPARSE_POINT = DeviceIoControl()
FILE_ATTRIBUTE_COMPRESSED = DeviceIoControl()
The function returns a non-zero value to indicate success otherwise zero.
To get more error information you can use the API GetLastError() function, error codes are in the WINERROR.H Visual C++ include file.
LOCAL lnResult
LOCAL lcFilename
#define FILE_ATTRIBUTE_READONLY 1
#define FILE_ATTRIBUTE_HIDDEN 2
#define FILE_ATTRIBUTE_SYSTEM 4
#define FILE_ATTRIBUTE_DIRECTORY 16
#define FILE_ATTRIBUTE_ARCHIVE 32
#define FILE_ATTRIBUTE_ENCRYPTED 64
#define FILE_ATTRIBUTE_NORMAL 128
#define FILE_ATTRIBUTE_TEMPORARY 256
#define FILE_ATTRIBUTE_SPARSE_FILE 512
#define FILE_ATTRIBUTE_REPARSE_POINT 1024
#define FILE_ATTRIBUTE_COMPRESSED 2048
#define FILE_ATTRIBUTE_OFFLINE 4096
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 8192
DECLARE INTEGER SetFileAttributes in KERNEL32 ;
STRING FileName, INTEGER Attributes
DECLARE INTEGER GetLastError in KERNEL32
lcFilename = "C:\FILE.TXT"
lnResult = SetFileAttributes(lcFilename, FILE_ATTRIBUTE_READONLY)
if lnResult = 0
wait window "Could not set the attribute, GetLastError() returns " + ;
alltrim(str(GetLastError()))
else
wait window "File set to read-only."
endif
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement