Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between FILE_WRITE_DATA and FILE_APPEND_DATA

Tags:

windows

winapi

I want to open a file for writing using CreateFile(). If the file exists, I will set the file pointer to the end and then write data using WriteFile(). If it doesn't exist, I'll write at the beggining of the file.

Should I use FILE_APPEND_DATA or should I use FILE_WRITE_DATA or maybe FILE_WRITE_DATA|FILE_APPEND_DATA in the dwDesiredAccess parameter of CreateFile()?

Isn't the writing at the end is also a writing, so why is there FILE_APPEND_DATA?

like image 628
CITBL Avatar asked Sep 05 '25 09:09

CITBL


1 Answers

why is there FILE_APPEND_DATA?

FILE_APPEND_DATA automatically writes to the end of the file so that you do not have to call SetFilePointer/Ex() manually before writing. FILE_WRITE_DATA does not do that.

like image 132
Remy Lebeau Avatar answered Sep 08 '25 12:09

Remy Lebeau