Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Output file from lisp - question

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
237 Views, 4 Replies

Output file from lisp - question

I have a question :
I write an output fil from lisp with severallines.
Can i overwrite a specific line with new data ??

I know there are a few options for an output file:

r Open for reading.

w Open for writing. If filename does not exist, a new file is created and
opened. If filename already exists, its existing data is overwritten. Data
passed to an open file is not actually written until the file is closed with
the close function.

a Open for appending. If filename does not exist, a new file is created and
opened. If filename already exists, it is opened and the pointer is
positioned at the

I can always read first the data and then overwrite the complete file, but
this is more complicated

Please help
Ysbrand Haagsma
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Y. Haagsma schreef in berichtnieuws
79D97EA13281AD47C959C2C61F248B78@in.WebX.maYIadrTaRb...
> I have a question :
> I write an output fil from lisp with severallines.
> Can i overwrite a specific line with new data ??
>
> I know there are a few options for an output file:
>
> r Open for reading.
>
> w Open for writing. If filename does not exist, a new file is created and
> opened. If filename already exists, its existing data is overwritten. Data
> passed to an open file is not actually written until the file is closed
with
> the close function.
>
> a Open for appending. If filename does not exist, a new file is created
and
> opened. If filename already exists, it is opened and the pointer is
> positioned at the
>
> I can always read first the data and then overwrite the complete file, but
> this is more complicated

this is you only option, you can't replace a line

>
> Please help
> Ysbrand Haagsma
>
>
Message 3 of 5
Anonymous
in reply to: Anonymous

or the same answer in dutch

als je een regel in een textfile wil vervangen, moet je de hele file lezen
en herschrijven
Message 4 of 5
Anonymous
in reply to: Anonymous

You can do this by opening the original file for read, and put each line into a
list.
(setq list (cons (read-line RFIL) list)
Then close the read file
Reverse the list, it is backwards
Then open a the file for write (the old file is destroyed, but you have it in
the list
write the lines that are OK to the file
as you cycle through the list you are looking for the line you want to replace
(foreach X list (if (/= TXT RTXT)(write-line X WFIL)(write-line NEWTXT WFIL))
When you get to the replace line, add the new text
continue cycling through the list using write-line
close the file.

The snippets are the guts of what you need to code....

ddk

"Y. Haagsma" wrote:

> I have a question :
> I write an output fil from lisp with severallines.
> Can i overwrite a specific line with new data ??
>
> I know there are a few options for an output file:
>
> r Open for reading.
>
> w Open for writing. If filename does not exist, a new file is created and
> opened. If filename already exists, its existing data is overwritten. Data
> passed to an open file is not actually written until the file is closed with
> the close function.
>
> a Open for appending. If filename does not exist, a new file is created and
> opened. If filename already exists, it is opened and the pointer is
> positioned at the
>
> I can always read first the data and then overwrite the complete file, but
> this is more complicated
>
> Please help
> Ysbrand Haagsma
Message 5 of 5
Anonymous
in reply to: Anonymous

Ok dank je wel.


"Paul" wrote in message
news:11E66D376C6C8D0FE25B20126A7A6804@in.WebX.maYIadrTaRb...
> or the same answer in dutch
>
> als je een regel in een textfile wil vervangen, moet je de hele file lezen
> en herschrijven
>
>

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost