Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I have a file that I use to save data when the system is running and I wish to save data to it but before saving, I want to erase its old content so at the end I can only have the latest content in the file. For some reason I would like to achieve that without close the file handle.
I first thought about using ZwSetInformationFile to set the size to 0 but I remember that its not recommended to play with file size so I was wondering If any of you that have been down the path could provide any help.

I awaiting for a response.

Thank you.

What I have tried:

I have already tired ZwSetInformationFile where my intention is to change the file size but I'm not sure that the way to do it.
Posted
Updated 28-Feb-16 22:20pm

1 solution

You can use the FILE_OVERWRITE option on your call to ZwCreateFile routine (Windows Drivers)[^].
 
Share this answer
 
Comments
Wshwilfried 1-Mar-16 19:16pm    
Thank you, I'll try that.
Wshwilfried 6-Mar-16 21:10pm    
I just tried That but it is not giving what I want also it isn't much different from FILE_OVERWRITE_IF that I was using before posting my question. What I need is that when calling ZwWriteFile the file content get cleared before the new buffer get written to the corresponding file.
Wshwilfried 6-Mar-16 21:50pm    
I think I found it, I just Set the byte offset to 0 when calling ZwWritefile and since the buffers are of the same size it always get updated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900