Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with FOPEN() read/write 1

Status
Not open for further replies.

koolmill

Technical User
Jul 29, 2002
3
GB
I can create a text file using FCREATE() but read only.

If I close the file I can only open it using FOPEN() as read only.

I am using Windows 2000 and VFP 5.

Am I missing the point or doing something wrong?

Any help gratefully received.
 
Try forcing a read/write attribute:

FCREATE("myText.txt",0)
 
And if you want to get creative change the file attributes once you are finished with the file:
Code:
LPARAMETERS  lpFileName 

#DEFINE FILE_ATTRIBUTE_READONLY       1   
#DEFINE FILE_ATTRIBUTE_HIDDEN         2   
#DEFINE FILE_ATTRIBUTE_SYSTEM         4   
#DEFINE FILE_ATTRIBUTE_DIRECTORY     16   
#DEFINE FILE_ATTRIBUTE_ARCHIVE       32   
#DEFINE FILE_ATTRIBUTE_NORMAL       128   
#DEFINE FILE_ATTRIBUTE_TEMPORARY    512   
#DEFINE FILE_ATTRIBUTE_COMPRESSED  2048   
       
DECLARE SHORT SetFileAttributes IN kernel32; 
    STRING lpFileName, INTEGER dwFileAttributes 

DECLARE INTEGER GetFileAttributes IN kernel32 STRING lpFileName  

* read current attributes for this file 
dwFileAttributes = GetFileAttributes (lpFileName) 

IF dwFileAttributes = -1 
* the file does not exist 
    RETURN 
ENDIF 

IF dwFileAttributes > 0 
    * read-only attribute to be set 
    dwFileAttributes = BitOr(dwFileAttributes, FILE_ATTRIBUTE_READONLY) 
         
    * archive attribute to be removed 
    IF BitAnd(dwFileAttributes, FILE_ATTRIBUTE_ARCHIVE) = FILE_ATTRIBUTE_ARCHIVE 
        dwFileAttributes = dwFileAttributes - FILE_ATTRIBUTE_ARCHIVE 
    ENDIF 

    * setting selected attributes 
    = SetFileAttributes (lpFileName, dwFileAttributes) 
ENDIF

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top