I am wondering if there is a simple command in Tcl that I can append a
file to an existing file, or combine two files into one file ?
Thanks for the help.
Regards
S-Y. Chen
Here's one way...
- [open] fileA in append mode
- [open] fileB in read only mode
- [read] the contents of fileB and write it to fileA using [puts]
- [close] both files
So, the man pages on [open], [read], [puts], and [close] should give you
all you need.
Jeff
I know I can do it through open, read and close.....just want to see
if there is a command like
copy a+b c
Maybe not...so......I will open, read and close it anyway........
>> - [read] the contents of fileB and write it to fileA using [puts]
just these two steps have a shortcut: [fcopy]
>> - [close] both files
So: open fileA and fileB in their respective modes
fcopy $inputFd $appendtoFd
close both filedescriptors
>> So, the man pages on [open], [read], [puts], and [close] should give you
>> all you need.
same for fcopy, of course.
> copy a+b c
But that's three files: first, copy a to c (using [file copy a c]),
then use the recipe for appending b to c.
PS: if on unix, do it thusly: exec cat a b > c
If you tcllib, you can check the fileutil package:
package require fileutil
::fileutil::appendToFile b [::fileutil::cat a]
or
::fileutil::writeFile c [::fileutil::cat a b]
George
Thanks a lot !
S-Y. Chen