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  


/**
 Check that file/dir exists, in Neko
*/
 
var sys_exists = $loader.loadprim("std@sys_exists", 1)
var sys_file_type = $loader.loadprim("std@sys_file_type", 1)
var sys_command = $loader.loadprim("std@sys_command", 1)
 
var name = "input.txt"
$print(name, " exists as file: ", sys_exists(name), "\n")
 
$print(name = "docs", " exists as dir: ", sys_exists(name) && sys_file_type(name) == "dir", "\n")
$print(name = "neko", " exists as dir: ", sys_exists(name) && sys_file_type(name) == "dir", "\n")
 
$print(name = "/input.txt", " exists as file: ", sys_exists(name) && sys_file_type(name) == "file", "\n")
$print(name = "/docs", " exists as dir: ", sys_exists(name) && sys_file_type(name) == "dir", "\n")
$print(name = "/tmp", " exists as dir: ", sys_exists(name) && sys_file_type(name) == "dir", "\n")
 
/* bonus round */
name = "empty.txt"
var stat_size = $loader.loadprim("std@sys_stat", 1)(name).size
$print(name, " exists as empty file: ", sys_exists(name) && stat_size == 0, "\n")
 
name = "`Abdu'l-Bahá.txt"
$print(name, " exists as file: ", sys_exists(name) && sys_file_type(name) == "file", "\n")