Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Change file attributes
Message
From
30/09/1998 16:16:55
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00142446
Message ID:
00142552
Views:
29
>>(VFP6) How do I change attributes of a file (like make a file writable)?
>
>There's a sample in the Files or FAQ section - the easiest way is with an API call. The following sets/clears standard attributes, and non-standard attributes if you know the proper numeric mask for them:
>
>FUNCTION SetFileAttribs
>LPARAMETERS tcFileName, tcAttributeMask, tnAttributeBaseRef
>IF TYPE('tnAttributeBaseRef') # 'N'
>  *	No extended attributes mask suggested, so set no attributes for Base
>  tnAttributeBaseRef = 0
>ENDIF
>
>IF TYPE('tcAttributeMask') # 'C'
>  *	No attribute Mask sent - set no attributes, clear all set now
>   tcAttributeMask = ''
>ELSE
>   tcAttributeMask = UPPER(tcAttributeMask)
>ENDIF
>
>IF TYPE('tcFileName') # 'C'
>   *	Filename must be character
>   RETURN .F.
>ENDIF
>
>LOCAL aFiles[1,5], nAttribs
>IF ADIR(aFiles,FULLPATH(tcFileName),'SHR') # 1
>   *	File must exist and not be a wildcard reference
>   RETURN .F.
>ENDIF
>
>IF 'D' $ aFiles[1,5] OR ;
>   'V' $ aFiles[1,5]
>   *	File must not be a directory or Volume label
>   RETURN .F.
>ENDIF
>
>*	R = Read-only   	1
>*	H = Hidden		2
>*	S = System		4
>*	A = Archive		32
>*
>*	Any other attribute must be specified via the
>*       tnAttributebaseRef parameter
>
>nAttribs = tnAttributeBaseRef + ;
>			IIF('R' $ tcAttributeMask, 1, 0) + ;
>			IIF('H' $ tcAttributeMask, 2, 0) + ;
>			IIF('S' $ tcAttributeMask, 4, 0) + ;
>			IIF('A' $ tcAttributeMask,32, 0)
>
>RETURN (SetFileAttributes(FULLPATH(tcFileName), nAttribs) = 1)
>
In order for the preceding to work, you must include the following DECLARE:
DECLARE INTEGER SetFileAttributes IN Kernel32 ;
	STRING cFileNameToAlter, ;
	INTEGER nAttributeMask
Gawd do I feel stoopid....
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform