ObjectScript - Appending to a file from another
– I want to “copy” a file to another, appending if the file already exists. The below code works, except it overwrites the new file, rather than append. The documentation says CopyFile will append
//Both files exists, so we can combine them
set tsc=##class(%File).CopyFile("D:\Files\Out\Vigilanz\AD_Lawson10132020.txt","D:\Files\Out\Vigilanz\employee10132020.txt"
if $$$ISOK(tsc)
{
W !, "SQL file copied"
}
else
{
Quit $$$ERROR($$$GeneralError,"SQL file not copied: "_SQLFileDate_" to "_EmployeeFile)
}
Thanks, Nora
Hi Nora,
The CopyFile method's documentation in the InterSystems class reference does say that the file will be overwritten.
https://docs.intersystems.com/irislatest/csp/documatic/%25CSP.Documatic.cls?PAGE=CLASS&LIBRARY=%25SYS&CLASSNAME=%25Library.File#METHOD_CopyFile
This documentation may help you with the appending:
Sequential File I/O
Hi Nora! Long time
Something like this should do the trick, assuming the file to be appended to is named "spoo.txt" and the file from which you're appending is named "fleem.txt":