Removing bytes from a file (C++)

Soldato
Joined
7 Apr 2004
Posts
4,212
Hey,

I need a way to remove X number of bytes from a position inside a binary file.

Currently all I can think up is this:
Code:
-Read everything from the start of file upto the position of the first byte to remove.
-Write this out to a temp file
-Read everything from the last byte to be removed to EOF.
-Append this to temp file
-Delete original
-Rename temp file to original file name.
This algorithm however will require (TotalSize - BytesToRemove) in free space on the disk to operate, and as my file could be pretty big I would really like to avoid this requirement if possible?

Are there any alternative solutions?

Thanks,
Jack
 
Back
Top Bottom