On Wed, Oct 26, 2011 at 3:54 PM, David Lum <[email protected]> wrote: > This works fine but strikes me as overly clunky, is there a more elegant way > to add to the front of a .CSV file?
In a word: No. Inserting data into a file -- any kind of file -- always requires rewriting the entire file from that point on.[1] That's just how computers work.[2] Programs which provide the illusion of insert are either (A1) rewriting the entire file all the time anyway, or (A2) doing things behind the scenes to make it look like an insert. An example of A1 would be almost all text editors: When you save, the entire file is overwritten each time. A2 typically means the program does updates in random-access fashion, and keeps some kind of index or reference list that provides a perceived order. Inserting new data would actually append to the end of the file, and then the index is updated to say where the new data should appear in the perceived order. Most databases work this way. -- Ben [1] Well, maybe there's a way to tell some OSes to reorganize things at the block level, but it would only be useful for block-aligned data, in which case you're already doing your own file housekeeping, so you wouldn't need the syscall in the first place. [2] The world's a big place. It wouldn't surprise me to find out that some obscure computers, or obscure filesystems, work differently. But as a general rule, this applies. ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to [email protected] with the body: unsubscribe ntsysadmin
