File.exists

From MiniScript Wiki
Revision as of 03:39, 24 January 2021 by Mantic (talk | contribs) (Initial file.exists page.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In Mini Micro and command-line MiniScript, the file.exists function checks if a file or directory exists at the specified path.

Arguments

Parameter Name Meaning
filePath an absolute or relative path of the file or directory to be tested.


Return Meaning
1 (true) The file or directory exists.
0 (false) The file or directory does not exist.


Example

Test the existence of various files and directories:

if file.exists("/usr2") then print "/usr2 appears to be mounted!"
if file.exists("/usr2/myapp.ms") then print "myapp.ms is there!"

// Look for a file in the parent directory of the current working directory. 
if not file.exists("../output.txt") then
  file.writeLines "../output.txt", "This file will be created with this string at the top. Woot!"
else
  file.writeLines "../output.txt", "This file will be overwritten with a BETTER string at the top."
end if