Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to tag a filename as readonly programatically
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00760275
Message ID:
00760341
Vues:
9
http://www.news2news.com/vfp/?example=103&function=151
#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_NORMAL       128  
#DEFINE FILE_ATTRIBUTE_TEMPORARY    512  
#DEFINE FILE_ATTRIBUTE_COMPRESSED  2048  
      
DECLARE SHORT SetFileAttributes IN kernel32;
	STRING lpFileName, INTEGER dwFileAttributes

DECLARE INTEGER GetFileAttributes IN kernel32 STRING lpFileName 

LOCAL lpFileName
lpFileName = 'c:\yourfilename.txt'

* read current attributes for this file
dwFileAttributes = GetFileAttributes (lpFileName)

IF dwFileAttributes = -1
* the file does not exist
	RETURN
ENDIF

IF dwFileAttributes > 0
	* read-only attribute to be set
	dwFileAttributes = BitOr(dwFileAttributes, FILE_ATTRIBUTE_READONLY)
		
	* archive attribute to be removed
	IF BitAnd(dwFileAttributes, FILE_ATTRIBUTE_ARCHIVE) = FILE_ATTRIBUTE_ARCHIVE
		dwFileAttributes = dwFileAttributes - FILE_ATTRIBUTE_ARCHIVE
	ENDIF

	* setting selected attributes
	= SetFileAttributes (lpFileName, dwFileAttributes)
ENDIF
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform