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  


/* NetRexx */
options replace format comments java crossref symbols binary
 
runSample(arg)
return
 
-- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
method isExistingFile(fn) public static returns boolean
  ff = File(fn)
  fExists = ff.exists() & ff.isFile()
  return fExists
 
-- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
method isExistingDirectory(fn) public static returns boolean
  ff = File(fn)
  fExists = ff.exists() & ff.isDirectory()
  return fExists
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
  parse arg files
  if files = '' then files = 'input.txt F docs D /input.txt F /docs D'
  loop while files.length > 0
    parse files fn ft files
    select case(ft.upper())
      when 'F' then do
        if isExistingFile(fn) then ex = 'exists'
        else                       ex = 'does not exist'
        say 'File '''fn'''' ex
        end
      when 'D' then do
        if isExistingDirectory(fn) then ex = 'exists'
        else                            ex = 'does not exist'
        say 'Directory '''fn'''' ex
        end
      otherwise do
        if isExistingFile(fn) then ex = 'exists'
        else                       ex = 'does not exist'
        say 'File '''fn'''' ex
        end
      end
    end
 
  return
 