Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Changing the file attribute
Message
De
12/01/2000 05:34:50
 
 
À
12/01/2000 03:44:27
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00316755
Message ID:
00316779
Vues:
13
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
Fil
Voir

Click here to load this message in the networking platform