Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Change File From ReadOnly to ReadWrite?
Message
De
09/08/2004 09:30:13
 
 
À
09/08/2004 09:19:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00931742
Message ID:
00931746
Vues:
42
This message has been marked as the solution to the initial question of the thread.
>Is it possible to change a file from ReadOnly to ReadWrite in VFP?
>ADIR() has a flag ("R") that permits you to retrieve the names of files that are read only. I would like to change these to ReadWrite.
> I understand that if the file resides on a CD, its Read/Write attribute cannot be changed.
> When I copy files from a CD to a hard drive, the files are copied to the hard drive with ReadOnly status. I would like to change these to ReadWrite if possible.
> TIA

Chaim,

this should get you going
&& to do once
declare Integer GetFileAttributes in win32api string @
declare Integer SetFileAttributes in win32api string @, Integer

#IFNDEF	TRUE
	#define	TRUE	.T.
	#define	FALSE	.F.

#ENDIF

#DEFINE FILE_ATTRIBUTE_READONLY 	0x01
#DEFINE FILE_ATTRIBUTE_HIDDEN		0x02
#DEFINE FILE_ATTRIBUTE_SYSTEM		0x04
#DEFINE FILE_ATTRIBUTE_DIRECTORY	0x10
#DEFINE FILE_ATTRIBUTE_ARCHIVE		0x20
#DEFINE FILE_ATTRIBUTE_NORMAL		0x80
#DEFINE FILE_ATTRIBUTE_TEMPORARY	0x0100

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

Click here to load this message in the networking platform