help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to truncate a file after partly overwriting it


From: Philip Nienhuis
Subject: Re: How to truncate a file after partly overwriting it
Date: Sun, 9 Feb 2014 08:07:35 -0800 (PST)

Please Macy, asnwer below the mail, do not top post.
See below:


Macy wrote
> --- 

> address@hidden

>  wrote:
> 
> From: Philip Nienhuis <

> address@hidden

> >
> To: 

> help-octave@

> Subject: Re: How to truncate a file after partly overwriting it
> Date: Sat, 8 Feb 2014 13:32:15 -0800 (PST)
> 
> Macy wrote
>> clumsy, but might work for you.
>> 
>> take the first part you want and write it to file temp.txt
>> then open temp.txt as an append and write the new stuff
>> then overwrite your original file with the temp.txt file and erase
>> temp.txt.
>> 
>> 
>> --- 
> 
>> address@hidden
> 
>>  wrote:
>> 
>> From: Philip Nienhuis <
> 
>> address@hidden
> 
>> >
>> To: 
> 
>> help-octave@
> 
>> Subject: How to truncate a file after partly overwriting it
>> Date: Sat, 8 Feb 2014 09:45:59 -0800 (PST)
>> 
>> Hi,
>> 
>> I'd like to partly overwrite a text file starting from position X.
>> However,
>> the new part to be written is shorter than the rest of the original file
>> contents from X to EOF. Consequently, after the newly written part, the
>> remainder of the old contents show up.
>> So, how can I close & truncate the file after the end of the new part?
> 
> Thanks, I found similar solutions with google.
> Some mor goolging shows that my request perhaps looks obvious but isn't so
> easy. Matlab has the same limitations it seems.
> On *nix systems (incl. Mac OSX) there seems to be a "truncate"/"ftruncate"
> command, but I need it for Windows as well. AFAICS for MinGW these
> commands
> either don't work, or are buggy, or are still in development.
> 
> My point is that I want to replace part(s) of potentially very large XML
> files. These can get really big, so it is handy to keep as much file
> contents as possible on disk and not in memory.
> 
> Macy wrote:
> 
> Back in the days of DOS and the impact printer days, I used to add an
> 'unprintable' character to the file forcing it to have RESET to the
> printer and then that pesky EOF character.
> 
> More recently I've structured .bmp files doing similar thing [that is,
> MAKE a file], but in using pretty old formats. Don't know how to force an
> unprintable character into XML file, probably more importantly, no idea
> how to go back and make the 'header' predict where that EOF charcter is. 
> 
> But if really, really important might be worth a check. Modify your header
> AND add the EOF character.

I doubt if EOF chars really help out. I tried to write various control chars
to the end of the new file contents file to make fread() stop gobbling
characters from disk, but obviously that didn't work. Why? Because (AFAIK)
the inode/FAT/file-descriptor/block-header/whatever on disk, in the disk
directory administration, must be updated as well. Some system call is
required for that.

Philip




--
View this message in context: 
http://octave.1599824.n4.nabble.com/How-to-truncate-a-file-after-partly-overwriting-it-tp4661758p4661768.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]