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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateFile: Opening but not appending !!

Status
Not open for further replies.

sjmolloy

Programmer
Aug 23, 2001
14
GB
Hi all,
I am sure I am missing something really obvious here BUT..
I want to open file using CreateFile.
If it does not exist I want to create it and write to it...
If it already exists, I want to append to it.
To this end, I used
CreateFile(path,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,0,NULL);

(path is a variable name in my program).

This works the first time ie it creates the file but when I exit the application and then go back in again the CreateFile statement seems to wipe hte file contents....I NEED to append !!!

What should I be doing?
I can't find any previous threads on this one but I am sure I am not the first person who wanted to run this scenario ???
 
Unless you're avoiding MFC, consider using CFile.
Construct with the CFile::modeCreate And CFile::modeNoTruncate flags.
 
1.Try to add the OPEN_EXISTING flag, too.
2.Use SetFilePointer API to set the file pointer at the end of the file the start writing in the file.

HTH, s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top