Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set file readonly
Message
From
04/12/2017 02:08:29
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Miscellaneous
Thread ID:
01656088
Message ID:
01656090
Views:
49
>I want to set a file from read-write to read-only and copy the following code (from Google) to my program, but failed. Anyone can point out what is wrong?
>
>TIA
>Ben
>
>*--------------------------------------------
>FUNC changeattr
>DECLARE INTEGER SetFileAttributes IN kernel32 STRING @,INTEGER @
>PRIVATE cFn
>cFilename="e:\testingfa\testfile.txt"
>#DEFINE FILE_ATTRIBUTE_READONLY 0x1
>m=SetFileAttributes(@cFilename,FILE_ATTRIBUTE_READONLY)
>RETURN m
FUNCTION SetAttr
PARAMETER tFileName, tAttribute
tAttribute = UPPER(tAttribute)
Private nAttribute
nAttribute=0
If 'S'$tAttribute && System
   nAttribute = nAttribute + 4
Endif    
If 'H'$tAttribute && Hidden
   nAttribute = nAttribute + 2
Endif    
If 'R'$tAttribute && ReadOnly
   nAttribute = nAttribute + 1
Endif    
If 'A'$tAttribute && Archive
   nAttribute = nAttribute + 32
Endif    
If 'N'$tAttribute && Normal
   nAttribute = nAttribute + 128
Endif    
declare integer SetFileAttributes IN kernel32 STRING, INTEGER 
Return SetFileAttributes(tFileName,nAttribute)=1
Previous
Reply
Map
View

Click here to load this message in the networking platform