simple stuff--input as a variable

Started by tom, August 02, 2004, 04:49:23 PM

Previous topic - Next topic

tom

(print "filename? ")
(device (open (read-line) "write"))
(println "#!/usr/bin/newlisp n")
(println "; $Id$")
(print "; ")
(println (date (apply date-value (now)))"nn" )

(close (device))
(exit)


This works, however, my attempts to set or define



(device (open (read-line) "write"))



have not worked.  Something like,



(set 'a (open (read-line) "write"))



I want to check if 'a already exists, maybe manipulate the file name

later, stuff like that.  



did my question make sense?

Lutz

#1
what 'device' does, is redirecting all output from print/println (console output) do a file (device takes a file handle).



perhaps you should rather do:

(set 'fileName (read-line))
(if (not (file? fileName))                      
   (set 'fle (open fileName "write"))  ;; if the file does not exiist create it
   (ser 'fle (open fileName "append"))) ;; else append to it

(write-line (read-line) fle)  ;; write stuff from the keyboard into the file
...
...
...
(close fle)


To test the existence of a file you have to take the file name rather than the handle returned from 'open', once you opened the file for "write" you would have destroyed (reset to the beginning) the file you want perhaps to append to.



Lutz



ps: not sure if I completely understand your intentions, but hope it helps