Task

Verify that a file called     input.txt     and   a directory called     docs     exist.



This should be done twice:  

   once for the current working directory,   and
   once for a file and a directory in the filesystem root.


Optional criteria (May 2015):   verify it works with:

   zero-length files
   an unusual filename:     `Abdu'l-Bahá.txt  


BYTE lastError
 
PROC MyError(BYTE errCode)
  lastError=errCode
RETURN
 
BYTE FUNC FileExists(CHAR ARRAY fname)
  DEFINE PTR="CARD"
  PTR old
  BYTE dev=[1]
 
  lastError=0
  old=Error
  Error=MyError ;replace error handling to capture I/O error
 
  Close(dev)
  Open(dev,fname,4)
  Close(dev)
 
  Error=old ;restore the original error handling
 
  IF lastError=0 THEN
    RETURN (1)
  FI
RETURN (0)
 
PROC Test(CHAR ARRAY fname)
  BYTE exists
 
  exists=FileExists(fname)
  IF exists THEN
    PrintF("File ""%S"" exists.%E",fname)
  ELSE
    PrintF("File ""%S"" does not exist.%E",fname)
  FI
RETURN
 
PROC Main()
  Test("D:INPUT.TXT")
  Test("D:DOS.SYS")
RETURN