Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to make a file read only
Message
De
20/11/2007 03:05:34
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01270091
Message ID:
01270094
Vues:
14
>hI
>I use Fcreate, Fputs and Fclose to create a Txt file.
>At the end of my creation, I want to have the file read only.
>I know Fcreate can do this, but then I cant write to the file.
>Is there another way of doing this inside VFP?
>Regards,
>
>Gerard

This may help
#define	TRUE	.T.
#define	FALSE	.F.
*--------------------------------------------------------------------------
#define INVALID_FILE_ATTRIBUTES		(-1)

#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_ENCRYPTED		0x00000040
#define	FILE_ATTRIBUTE_NORMAL		0x00000080
#define	FILE_ATTRIBUTE_TEMPORARY		0x00000100
#define	FILE_ATTRIBUTE_SPARSE_FILE		0x00000200
#define	FILE_ATTRIBUTE_REPARSE_POINT	0x00000400
#define	FILE_ATTRIBUTE_COMPRESSED		0x00000800
#define	FILE_ATTRIBUTE_OFFLINE		0x00001000
#define	FILE_ATTRIBUTE_NOT_CONTENT_INDEXED	0x00002000

declare Integer GetFileAttributes in win32api string @
declare Integer SetFileAttributes in win32api string @, Integer

function FileResetReadOnly(FileName)
	local fa
	fa = GetFileAttributes(@m.FileName)
	
	if( m.fa == INVALID_FILE_ATTRIBUTES )
		return FALSE
	endif
	
	if( empty(bitand(m.fa, FILE_ATTRIBUTE_READONLY)) ) && file was not readonly
		return FALSE
	endif
	
	fa = bitand(m.fa, bitnot(FILE_ATTRIBUTE_READONLY))
	
	if( empty(SetFileAttributes(@m.FileName, m.fa)) )
		return FALSE
	endif
	
endfunc
*--------------------------------------------------------------------------
function FileSetReadOnly(FileName)
	local fa
	fa = GetFileAttributes(@m.FileName)
	
	if( m.fa == INVALID_FILE_ATTRIBUTES )
		return FALSE
	endif
	
	fa = bitor(m.fa, FILE_ATTRIBUTE_READONLY)
	
	if( empty(SetFileAttributes(@m.FileName, m.fa)) )
		return FALSE
	endif
	
endfunc
*--------------------------------------------------------------------------
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform