Write to file question...
I would like to be able to write data to files with numbers after them like so:
datafile1.txt
datafile2.txt
datafile3.txt
and so on.
What I have right now is this
(with-open-file (out "datafile.txt"
:direction :output :if-exists :append
:if-does-not-exist :create)
Which will give me a datafile.txt without a number.
How do I append my variable 'number' to the datafile?
Thank you in advance for your assistance.
-Colin
"Nonzero" <····@geneseo.edu> wrote in message ·································@posting.google.com...
> Write to file question...
>
> I would like to be able to write data to files with numbers after them like so:
>
> datafile1.txt
> datafile2.txt
> datafile3.txt
>
> and so on.
>
> What I have right now is this
>
> (with-open-file (out "datafile.txt"
> :direction :output :if-exists :append
> :if-does-not-exist :create)
>
> Which will give me a datafile.txt without a number.
>
> How do I append my variable 'number' to the datafile?
(with-open-file
(out (format nil "datafile~A.txt" number)
:direction :output :if-exists :append
:if-does-not-exist :create)
--
Geoff
····@geneseo.edu (Nonzero) writes:
> Write to file question...
>
> I would like to be able to write data to files with numbers after them like so:
>
> datafile1.txt
> datafile2.txt
> datafile3.txt
>
> and so on.
>
> What I have right now is this
>
> (with-open-file (out "datafile.txt"
> :direction :output :if-exists :append
> :if-does-not-exist :create)
>
> Which will give me a datafile.txt without a number.
>
> How do I append my variable 'number' to the datafile?
* (setf gg (format nil "bob~d.txt" 14) )
Warning: Declaring GG special.
bob14.txt
NIL
* gg
"bob14.txt"
should get you started, you may want to wrap the
whole thing in a let form though
marc
>
> Thank you in advance for your assistance.
>
> -Colin
Nonzero wrote:
> (with-open-file (out "datafile.txt"
> :direction :output :if-exists :append
> :if-does-not-exist :create)
>
> Which will give me a datafile.txt without a number.
>
> How do I append my variable 'number' to the datafile?
others showed you how to use format to build your filename, but since
you asked about appending...
(concatenate 'string "hello, " "world.")
=> "hello, world."
--
kenny tilton
clinisys, inc
http://www.tilton-technology.com/
---------------------------------------------------------------
"Cells let us walk, talk, think, make love and realize
the bath water is cold." -- Lorraine Lee Cudmore