Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Changing file attributes thru VFP or API?
Message
From
16/06/1998 03:46:39
Mark Hall
Independent Developer & Voip Specialist
Keston, Kent, United Kingdom
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00108427
Message ID:
00108540
Views:
375
>I am finding shelling out to DOS in my VFP application (under WinNT) to change file attributes from ReadOnly to ReadWrite to be a drag! I don't want to have a DOS window pop up on the screen, and when I use RUN /N2, the command doesn't always finish by the time I need to delete the file in code (yech). There must be some programmatic method to do this:
>
>If ReadOnly
> Make ReadWrite
>EndIf
>
>Even if I have to resort to an API!?!?
>
>TIA

Don't forget to preserve the other attributes.

e.g. This just flips the readonly attrib on autoexec.bat
LOCAL lnResult, lcFileName, lnAttributes

#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_NORMAL 0x00000080
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
#define FILE_ATTRIBUTE_ERROR 0xFFFFFFFF

DECLARE Integer SetFileAttributes IN Win32API String @, Integer
DECLARE Integer GetFileAttributes IN Win32API String @

lcFileName = "C:\Autoexec.bat" + CHR(0)

IF FILE( lcFileName)
*-- Get original attributes
lnAttributes = GetFileAttributes( @lcFileName)

*-- If Ok, Flip the ReadOnly attribute
IF lnAttributes <> FILE_ATTRIBUTE_ERROR
lnResult = SetFileAttributes( @lcFileName, BITXOR(lnAttributes, FILE_ATTRIBUTE_READONLY))
ENDIF
ENDIF
Regards
Mark

Microsoft VFP MCP
Menulib - OO Menus for VFP www.hidb.com/menulib
Previous
Reply
Map
View

Click here to load this message in the networking platform