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  


 
checkFile[filename] :=
{
   file = newJava["java.io.File", [filename]]
   if file.exists[] and file.isFile[]
      println["$filename is a file"]
   else
      println["$filename is not a file"]
}
 
checkDir[filename] :=
{
   file = newJava["java.io.File", [filename]]
   if file.exists[] and file.isDirectory[]
      println["$filename is a directory"]
   else
      println["$filename is not a directory"]
}
 
checkFile["input.txt"]
checkFile["/input.txt"]
checkDir["docs"]
checkDir["/docs"]
 
// This tests the "unusual" filename with various Unicode
// normalizations that would look identical to a human
// For example, the á character could be written as either
// the Unicode sequences
//    \u00e1   ('LATIN SMALL LETTER A WITH ACUTE')
// or
//    \u0061\u0301  ('LATIN SMALL LETTER A' 'COMBINING ACUTE ACCENT')
unusual = "`Abdu'l-Bahá.txt"    
checkFile[unusual]
checkFile[normalizeUnicode[unusual, "NFC"]]
checkFile[normalizeUnicode[unusual, "NFD"]]
 