Question
· Nov 15, 2017

syntax for open/use/read statements on a simple ms-dos text file.

Can anyone suggest suitable Cache ObjectScript syntax for open/use/read statements on a simple ms-dos text file.
I've tried various examples seen on the web but they appear to be implementation specific.
I used MSM MUMPS many years ago but am now retired & would like to write a few simple routines for my own amusement & mental challenge.
I am using the free Version of Cache (V 2017.1) on my Windows 10 PC. The installation file was CachePCkit_x64.exe
My apologies for this query being very basic.

Discussion (4)0
Log in or sign up to continue

Welcome back!

infile  ; simple file read
  set filename="C\mydir\myfile.txt"
  set $ZTRAP="end"
  open filename:("R"):0 else  Write "file error"
  for line=1:1 use filename read text use 0 write text,! 
end
 close filename
  set $ZTRAP=""
  use 0 write "Done",
  quit

it's not so sophisticated and I used the end-of-file error to exit

This is also available in class %Library.File with lot more comfort 
http://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?P...

HTH
 

You might use $ZEOF to check for file end.

It should be enabled first:

do $system.Process.SetZEOF(1)

Then you can read file line-by-line as follows:

  do $system.Process.SetZEOF(1)
  set filename = "c:\temp\qq.txt"
  open filename:"R":2
  if '$Test {
    write "cannot open file ", filename, !
    quit
  }
  for  {
    use filename read str
    quit:$ZEOF=-1
    use $Principal write str,!
  }
  close filename