Difference between revisions of "File.child"

From MiniScript Wiki
Jump to navigation Jump to search
(Created page with "In Mini Micro and command-line MiniScript, the <c>file.child</c> function combines a parent path with a child subpath or file name. === Arguments === {| class="...")
 
 
Line 1: Line 1:
 
In [[Mini Micro]] and [[command-line MiniScript]], the <c>[[file]].child</c> function combines a parent path with a child subpath or file name.  
 
In [[Mini Micro]] and [[command-line MiniScript]], the <c>[[file]].child</c> function combines a parent path with a child subpath or file name.  
 +
 +
See also: [[file.children]]
  
 
=== Arguments ===
 
=== Arguments ===

Latest revision as of 23:08, 11 July 2021

In Mini Micro and command-line MiniScript, the file.child function combines a parent path with a child subpath or file name.

See also: file.children

Arguments

Parameter Name Meaning
basePath absolute or relative parent path (with or without a trailing path separator)
subpath partial path or file name

Usage Notes

This method will insert the correct path separator for the platform it's running on. On Linux, Mac OS, and Mini Micro, the path separator is a forward slash (/); but on Windows it is a backslash (\). By using this method instead of combining path parts manually, you can avoid hard-coding a particular path separator, and so write more portable code.

file.child will also correctly handle the case where the base path ends in a path separator, i.e., it only adds a path separator when one is needed.

Example

This prints the full path to a file called "test.txt" in the current directory.

print file.child(file.curdir, "test.txt")

The exact output of the above depends on the platform and the current working directory. For example, if you are on Mini Micro and in the default /usr directory, then this prints /usr/test.txt.