Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Call to mak file Readonly and back again.
Message
From
26/11/2002 10:13:27
 
 
To
26/11/2002 09:56:22
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00726982
Message ID:
00727000
Views:
5
>I am trying to find a Windows API call that will allow me to change a file's property to readonly, and back again. I'm currently using the the old RUN command, but that makes the DOS window display and is really annoying. Placing the /N (NOWAIT) works is some instances where the following command is not effected. I'd really like to do this as clean as possible. Any ideas out there?
>
>Jason.

Jason,

If you want the api
#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

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

*--------------------------------------------------------------------------
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
Previous
Reply
Map
View

Click here to load this message in the networking platform