Shrinking the File Length

Hi, I've got a file that I use for storing data as records, now adding records works fine, but what if I want to remove records and reclaim the unused space? Is there an easier way to do this other than rewriting the whole file? All the examples I've seen actually kill the file and rewrite all the data, this isn't a problem if the file is small, but thinking ahead it may cause a delay if the file is large.

[419 byte] By [PsychUK] at [2007-12-23]
# 1

You could use a database for this.

ReneeC at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2

Yes I know, but I found using saved data structures alot better for alot of reasons, I dont get any runtime exceptions now, I originally used a database, and found it hung the application at startup due to the servers starting up, etc, but that's another discussion. I use List (Of T) now, does more or less exactly the same thing for what I want and doesnt need any external processes to keep it running.

PsychUK at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3

If that's the case (flat files), you have to rewrite the whole file (Technically, I think you could rewrite the end of file location using some win32 APIs but I think it'd cause more problems than what it's worth).

SJWhiteley at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 4

Thanks SJ.

I was thinking that was the case, but I wasnt sure if there was a method somewhere I had overlooked, maybe I'll put a backup routine on another thread that doesnt save deleted records, anyways, its no big deal. Thanks again.

PsychUK at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 5
I think everyone feels that way about files ("why the heck do I have to rewrite the dictionary just add the word 'doh' to it?") But it's the way it is . (of course, anyone is free to write their own more efficient operating system, file handling system, user interface...).
SJWhiteley at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...