You want to append the contents of several files to a single file. For example you want the contents of the file foo.txt to be the contents of bar.txt and baz.txt. In the UNIX shell you might write:
(require (lib"port.ss"))
;; file-append : (U path string) ... -> void
;;
;; Copys the contents of the src files to dest
(define (file-appenddest . src)
(with-output-to-filedest
(lambda ()
(copy-port
(applyinput-port-append#t (mapopen-input-filesrc))
(current-output-port)))))
The key parts of this function are the calls to input-port-append and copy-port. Using input-port-append we first make one input port that returns in succession the data contained in each src file. We then efficiently copy the data to the output port using copy-port. The #t parameter to input-port-append tells it to close the given ports when they reach the end of the file.
The functions used in this example have many uses outside of copying files. For example, to efficiently copy the contents of a port to a string you could use copy-port and open-output-string. See FileRead for more examples.