Jump to content

Create a text file first and append some text later


kasra

Recommended Posts

Hi friends.

Please help....

Assume that in the first time i have created a text-file and open it and write some text on it and then closed it by using lisp routine.

Later, i whould open that file again and append some text at the next line in the file by using lisp routine.

How is it possible to append some text at the next line in the file with out missing texts created before?

thanks for your attention.

Link to comment
Share on other sites

Open the file using open function and "a" (append) as access mode:

 

(setq MyInputObj (open MyFilePath "a"))

 

Regards,

Link to comment
Share on other sites

Perhaps something like ;

 


(defun c:DoIt (/ filename fn line1 line2)
 (setq fileName "C:\\MyTextFile.txt"
       Line1    "A is for apple red and bright"
       Line2    "B is for bed where I sleep at night"
 )
 (or (findfile fileName) (progn (setq fn (open fileName "w")) (close fn)))
 ;;
 ;;
 ;; bla-bla
 ;;
 (setq fn (open fileName "a"))
 (write-line Line1 fn)
 (close fn)
 ;;
 ;;
 ;; bla-bla
 ;;
 (setq fn (open fileName "a"))
 (write-line Line2 fn)
 (close fn)
 (princ)
)


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...