LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Deleting characters from a file

Hello,
While my program is running, everything the user does is kept in a debug file. Now I am trying to limit the size of this file. This means, when the file has reached a certain amount of characters, old characters have to be deleted before I insert new ones. The characters to be deleted are not the first ones in the file, since I have a file header (date, time, version, ...) that I don't want to remove when my file is growing.
I know how to write to a file (I use the WriteFile function) but I don't know how to delete from a file. I guess I first have to move the File Pointer (using SetFilePtr) to the place of the character I want to delete, but then how do I delete this character?
 
Thanks for all help,
Wim
0 Kudos
Message 1 of 3
(3,085 Views)

as far as I know you cannot delete a byte from the middle of a file.  one easy safe way is that you can write a new file with the contents of the old file up to location x and then continue writing the new file from old file location x+y to the end, and then rename the file.   you can also do this in place if you are careful not to overwrite data you might want later and to be aware of where you are in the file.  in your case a fixed header size, and a fixed removal size would make things easy and quick, but that depends on how your data is.

if someone knows how do delete a byte from the middle of a file please let us all know.

 

  

0 Kudos
Message 2 of 3
(3,074 Views)

Hello Wim.

You could try "File Mapping" in the Windows Platform SDK. I have never used this, but it appears to support what you want to do.
 
Regards,
Colin.
0 Kudos
Message 3 of 3
(3,056 Views)