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: Francesco Potortì
Subject: Re: How to truncate a file after partly overwriting it
Date: Sun, 09 Feb 2014 19:17:47 +0100

>>>> From: Philip Nienhuis
>>>> 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?
>
>>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.
>
>>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:
>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.

Hm.  If I understand correctly, this was printer-specific.

>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. 

XML files are Unicode text files.  The ASCII non -printable characters
are not valid in XML.  There is no EOF character in XML.

>But if really, really important might be worth a check. Modify your
>header AND add the EOF character.

The "header" of an XML file has no info on the file lenght, and there is
no EOF character, unless I'm missing something obvious.

-- 
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it


reply via email to

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