Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Difference between revisions of "Nasal library/os.path"

From FlightGear wiki
Jump to: navigation, search
m (set(): Fix minor error in example 2)
(Finish)
 
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Nasal Navigation|nocat=1}}
 
{{Nasal Navigation|nocat=1}}
This page contains documentation for the '''<code>os.path</code> namespace''' in [[Nasal]]. This namespace implements tools (from SGPath) for manipulating file paths. Everything in the <code>geo</code> namespace is sourced from {{flightgear file|src/Scripting/NasalSGPath.cxx}}
+
This page contains documentation for the '''<code>os.path</code> namespace''' in [[Nasal]]. This namespace implements tools (from SGPath) for manipulating file paths. Everything in the <code>os.path</code> namespace is sourced from {{flightgear file|src/Scripting/NasalSGPath.cxx}}
  
 
{{tip|Copy & paste the examples into your [[Nasal Console]] and execute them to see what they do.|width=70%}}
 
{{tip|Copy & paste the examples into your [[Nasal Console]] and execute them to see what they do.|width=70%}}
  
{{note|Everything here was added to FlightGear 3.0.|width=70%}}
+
{{note|Everything here was added to FlightGear 3.0. (released [[FlightGear History#Release timeline|February 2014]])|width=70%}}
  
 
== Class ==
 
== Class ==
Line 12: Line 12:
 
|text = A pseudo-class (actually a Nasal ghost). This is the main class that stores and allows manipulation of file paths. This is also integrated into the <code>os.path</code>.
 
|text = A pseudo-class (actually a Nasal ghost). This is the main class that stores and allows manipulation of file paths. This is also integrated into the <code>os.path</code>.
 
}}
 
}}
 
 
==== new() ====
 
==== new() ====
 
{{Nasal doc
 
{{Nasal doc
Line 19: Line 18:
 
|param1 = path
 
|param1 = path
 
|param1text = Optional string specifying the filepath. If not given, the path will default to [[$FG_ROOT]]
 
|param1text = Optional string specifying the filepath. If not given, the path will default to [[$FG_ROOT]]
|example1 = var path = os.path.new();
+
|example1 = var path = os.path.new("C:/Windows"); # Windows filepath
print(path.realpath); # will print $FGROOT
+
|example2 = var path = os.path.new("C:/Windows"); # Windows filepath
+
 
# var path = os.path.new("/usr/bin/"); # Unix filepath
 
# var path = os.path.new("/usr/bin/"); # Unix filepath
 
print(path.realpath);
 
print(path.realpath);
 
}}
 
}}
 
 
==== set() ====
 
==== set() ====
 
{{Nasal doc
 
{{Nasal doc
Line 33: Line 29:
 
|param1text = Optional string specifying the filepath. If not given, the path will be set to [[$FG_ROOT]]
 
|param1text = Optional string specifying the filepath. If not given, the path will be set to [[$FG_ROOT]]
 
|example1 = var path = os.path.new("C:/Windows");
 
|example1 = var path = os.path.new("C:/Windows");
# var path = os.path.new("/usr/bin/"); # alternative Unix filepath
 
print(path.realpath);
 
path.set();
 
print(path.realpath); # will print $FG_ROOT
 
|example2 = var path = os.path.new("C:/Windows");
 
 
# var path = os.path.new("/usr/bin/"); # alternative Unix filepath
 
# var path = os.path.new("/usr/bin/"); # alternative Unix filepath
 
print(path.realpath);
 
print(path.realpath);
Line 44: Line 35:
 
print(path.realpath); # prints new path
 
print(path.realpath); # prints new path
 
}}
 
}}
 
 
==== append() ====
 
==== append() ====
 +
{{Nasal doc
 +
|syntax = os.path.append([path]);
 +
|text = Appends a new part to the filepath.
 +
|param1 = path
 +
|param1text = Optional string specifying the new part to add to the filepath. If not given, the resultant path will not change.
 +
|example1 = var path = os.path.new("C:/Windows");
 +
# var path = os.path.new("/usr/"); # alternative Unix filepath
 +
print(path.realpath);
 +
path.append("Program Files");
 +
# path.append("bin"); # alternative Unix filepath
 +
print(path.realpath); # prints "C:/Windows/Program Files" or "/usr/bin"
 +
}}
 
==== concat() ====
 
==== concat() ====
 +
{{Nasal doc
 +
|syntax = os.path.concat([path]);
 +
|text = Appends a new part to the filepath.
 +
|param1 = path
 +
|param1text = Optional string specifying part to concat to the existing filepath. Note that this will simply add the string to the end of the path without adding a separator. If not given, the resultant path will not change.
 +
|example1 = var path = os.path.new("C:/Windows");
 +
# var path = os.path.new("/usr"); # alternative Unix filepath
 +
print(path.realpath);
 +
path.concat("/Program Files");
 +
# path.concat("/bin"); # alternative Unix filepath
 +
print(path.realpath); # prints "C:/Windows/Program Files" or "/usr/bin"
 +
}}
 
==== exists() ====
 
==== exists() ====
 +
{{Nasal doc
 +
|syntax = os.path.exists();
 +
|text = Returns 1 (true) if the path exists and 0 (false) if it does not.
 +
|example1 = var path = os.path.new("C:/Windows");
 +
# var path = os.path.new("/usr"); # alternative Unix filepath
 +
print(path.exists()); # prints 1 (true)
 +
path.set("C:/Window");
 +
# path.set("/r"); # alternative Unix filepath
 +
print(path.exists()); # prints 0 (false)
 +
}}
 
==== canRead() ====
 
==== canRead() ====
 +
{{Nasal doc
 +
|syntax = os.path.canRead();
 +
|text = Returns 1 (true) if the path can be read (from Nasal) and 0 (false) if it cannot. This follows the rules for allowed paths.
 +
|example1 = var path = os.path.new("C:/Windows");
 +
# var path = os.path.new("/usr"); # alternative Unix filepath
 +
print(path.canRead()); # prints 0 (false)
 +
path.set(getprop("sim/fg-home"));
 +
print(path.canRead()); # prints 1 (true)
 +
}}
 
==== canWrite() ====
 
==== canWrite() ====
 +
{{Nasal doc
 +
|syntax = os.path.canWrite();
 +
|text = Returns 1 (true) if the path can be written to (from Nasal) and 0 (false) if it cannot. This follows the rules for allowed paths.
 +
|example1 = var path = os.path.new("C:/Windows");
 +
# var path = os.path.new("/usr"); # alternative Unix filepath
 +
print(path.canWrite()); # prints 0 (false)
 +
path.set(getprop("sim/fg-home") ~ "/txt.log");
 +
print(path.canWrite()); # prints 1 (true)
 +
}}
 
==== isFile() ====
 
==== isFile() ====
 +
{{Nasal doc
 +
|syntax = os.path.isFile();
 +
|text = Returns 1 (true) if the path points to a file and 0 (false) if it points to a directory. Note that the path must also exist.
 +
|example1 = var path = os.path.new(getprop("sim/fg-root"));
 +
print(path.isFile()); # prints 0 (false)
 +
path.append("Nasal/io.nas");
 +
print(path.isFile()); # prints 1 (true)
 +
}}
 
==== isDir() ====
 
==== isDir() ====
 +
{{Nasal doc
 +
|syntax = os.path.isDir();
 +
|text = Returns 1 (true) if the path points to a directory and 0 (false) if it points to a file. Note that the path must also exist.
 +
|example1 = var path = os.path.new(getprop("sim/fg-root"));
 +
print(path.isDir()); # prints 1 (true)
 +
path.append("Nasal/io.nas");
 +
print(path.isDir()); # prints 0 (false)
 +
}}
 
==== isRelative() ====
 
==== isRelative() ====
 +
{{Nasal doc
 +
|syntax = os.path.isRelative();
 +
|text = Returns 1 (true) if the path is relative and 0 (false) if it is not.
 +
|example1 = var path = os.path.new(getprop("sim/fg-root"));
 +
path.set("./Nasal");
 +
print(path.isRelative()); # prints 1 (true)
 +
}}
 
==== isAbsolute() ====
 
==== isAbsolute() ====
 +
{{Nasal doc
 +
|syntax = os.path.isAbsolute();
 +
|text = Returns 1 (true) if the path is an absolute path and 0 (false) if it is not.
 +
|example1 = var path = os.path.new(getprop("sim/fg-root"));
 +
print(path.isAbsolute()); # prints 1 (true)
 +
}}
 
==== isNull() ====
 
==== isNull() ====
 +
{{Nasal doc
 +
|syntax = os.path.isNull();
 +
|text = Returns 1 (true) if the path is null and 0 (false) if it is not.
 +
|example1 = var path = os.path.new();
 +
print(path.isNull());
 +
}}
 
==== create_dir() ====
 
==== create_dir() ====
 +
{{Nasal doc
 +
|syntax = os.path.create_dir();
 +
|text = Creates the parent of the path as a directory. This will only work if the path is absolute and considered as writable by {{func link|fgValidatePath()|link=https://sourceforge.net/p/flightgear/flightgear/ci/next/tree/src/Main/util.cxx#l142}} (typically okay under [[$FG_HOME]]/Export).
 +
|example1 = var path = os.path.new(getprop("/sim/fg-home") ~ "/Export/test/demo.txt");
 +
path.create_dir(); # Creates $FG_HOME/Export/test/
 +
}}
 
==== remove() ====
 
==== remove() ====
 +
{{Nasal doc
 +
|syntax = os.path.remove();
 +
|text = Removes the last element of the path from the file directory. This will only work if the path is absolute and deletion of the file is permitted by the file permissions (typically okay under [[$FG_HOME]]/Export). Note that on Windows, deletion of read-only files are never permitted.
 +
|example1 = var path = os.path.new(getprop("/sim/fg-home") ~ "/Export/demo.txt");
 +
var file = io.open(path.realpath, "w");
 +
io.write(file, 'Hello, World' ~ "\n");
 +
io.close(file);
 +
print(path.exists()); # prints "1"
 +
 +
path.remove();
 +
print(path.exists()); # prints "0"
 +
|example2 = var path = os.path.new(getprop("/sim/fg-home") ~ "/Export/test");
 +
path.create_dir();
 +
path.remove(); # folder "/test" is removed
 +
}}
 
==== rename() ====
 
==== rename() ====
 +
{{Nasal doc
 +
|syntax = os.path.rename(new_name);
 +
|text = Renames the last element of the path from the file directory. This will only work if the path is absolute, the old path is both readable and writable, the new path is writable.
 +
|example1 = var path = os.path.new(getprop("/sim/fg-home") ~ "/Export/demo.txt");
 +
var file = io.open(path.realpath, "w");
 +
io.write(file, 'Hello, World' ~ "\n");
 +
io.close(file);
 +
path.rename(getprop("/sim/fg-home") ~ "/Export/demo1.txt");
 +
print(path.realpath); # prints $FG_HOME/Export/demo1.txt
 +
}}
 
==== realpath ====
 
==== realpath ====
 +
{{Nasal doc
 +
|syntax = os.path.realpath;
 +
|text = A string variable that gives the full file path. This should only be used when the path is an absolute path. If the path is relative, it will simply be appended to the FlightGear folder (the level up from [[$FG_ROOT]]).
 +
|example1 = var path = os.path.new(getprop("/sim/fg-home"));
 +
print(path.realpath); # prints the absolute path of $FG_HOME
 +
}}
 
==== file ====
 
==== file ====
 +
{{Nasal doc
 +
|syntax = os.path.file;
 +
|text = A string variable that gives the last part of the filepath.
 +
|example1 = var path = os.path.new(getprop("/sim/fg-home"));
 +
print(path.file); # prints "flightgear.org"
 +
}}
 
==== dir ====
 
==== dir ====
 +
{{Nasal doc
 +
|syntax = os.path.dir;
 +
|text = A string variable that gives all of the filepath except the last element (see <code>os.path.file</code> above).
 +
|example1 = var path = os.path.new("Program Files/temp/text.txt");
 +
print(path.dir); # prints "Program Files/temp"
 +
}}
 
==== base ====
 
==== base ====
 +
{{Nasal doc
 +
|syntax = os.path.base;
 +
|text = A string variable that gives all of the filepath except the extension of the file. If the filepath points to a folder, it has the same value as [[#realpath|realpath]].
 +
|example1 = var path = os.path.new("Program Files/temp/text.txt");
 +
print(path.base); # prints "Program Files/temp/text"
 +
}}
 
==== file_base ====
 
==== file_base ====
 +
{{Nasal doc
 +
|syntax = os.path.file_base;
 +
|text = A string variable that gives the file name without the extension. If the filepath points to a folder, it will simply be the folder name.
 +
|example1 = var path = os.path.new("Program Files/temp/text.txt");
 +
print(path.file_base); # prints "text"
 +
}}
 
==== extension ====
 
==== extension ====
 +
{{Nasal doc
 +
|syntax = os.path.extension;
 +
|text = A string variable that gives the file's extension. If the filepath points to a folder, it will be an empty string.
 +
|example1 = var path = os.path.new("Program Files/temp/text.txt");
 +
print(path.extension); # prints "txt"
 +
}}
 
==== lower_extension ====
 
==== lower_extension ====
 +
{{Nasal doc
 +
|syntax = os.path.lower_extension;
 +
|text = A string variable that gives the file's extension, but converted to lowercase. If the filepath points to a folder, it will be an empty string.
 +
|example1 = var path = os.path.new("Program Files/temp/text.TXT");
 +
print(path.lower_extension); # prints "txt"
 +
}}
 
==== complete_lower_extension ====
 
==== complete_lower_extension ====
 +
{{Nasal doc
 +
|syntax = os.path.complete_lower_extension;
 +
|text = This is to be used when a file has a double extension (e.g., <code>.tar.gz</code>). It also converts it to lowercase.  If the filepath points to a folder, it will be an empty string.
 +
|example1 = var path = os.path.new("Program Files/temp/text.TAR.GZ");
 +
print(path.complete_lower_extension); # prints "tar.gz"
 +
}}
 
==== str ====
 
==== str ====
 +
{{Nasal doc
 +
|syntax = os.path.str;
 +
|text = A string giving the path that the instance points too.
 +
This is to be used when a file has a double extension (e.g., <code>.tar.gz</code>). It also converts it to lowercase.  If the filepath points to a folder, it will be an empty string.
 +
|example1 = var path = os.path.new("../temp/text.txt");
 +
print(path.str); # prints "../temp/text.txt"
 +
|example2 = var path = os.path.new(getprop("sim/fg-home"));
 +
print(path.str); # prints the full path to $FG_HOME
 +
}}
 
==== mtime ====
 
==== mtime ====
 +
{{Nasal doc
 +
|syntax = os.path.mtime;
 +
|text = An integer giving the Unix time when the file or folder was last modified.
 +
|example1 = var path = os.path.new(getprop("sim/fg-home"));
 +
print(path.mtime); # prints a Unix time
 +
}}
  
 
== Functions ==
 
== Functions ==
 
=== desktop() ===
 
=== desktop() ===
 +
{{Nasal doc
 +
|syntax = os.path.desktop();
 +
|text = Creates and returns an <code>os.path</code> pointing to the desktop location.
 +
 +
{{Note|As of April 2018, this function does not work properly and returns the <code>/bin</code> folder.}}
 +
|example1 = var path = os.path.desktop();
 +
print(path.realpath);
 +
}}
 
=== standardLocation() ===
 
=== standardLocation() ===
 +
{{Nasal doc
 +
|syntax = os.path.standardLocation(location);
 +
|text = Creates and returns an <code>os.path</code> pointing to the standard location.
 +
 +
{{Note|As of April 2018, only supplying "HOME" to this function actually works. All the others do not work properly and return the <code>/bin</code> folder.}}
 +
|param1 = location
 +
|param1text = String specifying the standard location to use. May be one of <code>HOME</code>, <code>DESKTOP</code>, <code>DOWNLOADS</code>, <code>DOCUMENTS</code>, or <code>PICTURES</code>.
 +
|example1 = var path = os.path.standardLocation("HOME");
 +
print(path.realpath);
 +
}}
  
 
{{Nasal namespaces}}
 
{{Nasal namespaces}}

Latest revision as of 16:12, 22 April 2018

This page contains documentation for the os.path namespace in Nasal. This namespace implements tools (from SGPath) for manipulating file paths. Everything in the os.path namespace is sourced from flightgear/src/Scripting/NasalSGPath.cxx

Tip  Copy & paste the examples into your Nasal Console and execute them to see what they do.
Note  Everything here was added to FlightGear 3.0. (released February 2014)

Class

os.path

A pseudo-class (actually a Nasal ghost). This is the main class that stores and allows manipulation of file paths. This is also integrated into the os.path.

new()

os.path.new([path]);

Constructor function. Returns a new os.path instance. Note that the path must not violate the rules for allowed paths.

path
Optional string specifying the filepath. If not given, the path will default to $FG_ROOT

Example

var path = os.path.new("C:/Windows"); # Windows filepath
# var path = os.path.new("/usr/bin/"); # Unix filepath
print(path.realpath);

set()

os.path.set([path]);

Sets the filepath. Note that the path must not violate the rules for allowed paths.

path
Optional string specifying the filepath. If not given, the path will be set to $FG_ROOT

Example

var path = os.path.new("C:/Windows");
# var path = os.path.new("/usr/bin/"); # alternative Unix filepath
print(path.realpath);
path.set("C:/Windows/Program Files");
# path.set("/usr/"); # alternative Unix filepath
print(path.realpath); # prints new path

append()

os.path.append([path]);

Appends a new part to the filepath.

path
Optional string specifying the new part to add to the filepath. If not given, the resultant path will not change.

Example

var path = os.path.new("C:/Windows");
# var path = os.path.new("/usr/"); # alternative Unix filepath
print(path.realpath);
path.append("Program Files");
# path.append("bin"); # alternative Unix filepath
print(path.realpath); # prints "C:/Windows/Program Files" or "/usr/bin"

concat()

os.path.concat([path]);

Appends a new part to the filepath.

path
Optional string specifying part to concat to the existing filepath. Note that this will simply add the string to the end of the path without adding a separator. If not given, the resultant path will not change.

Example

var path = os.path.new("C:/Windows");
# var path = os.path.new("/usr"); # alternative Unix filepath
print(path.realpath);
path.concat("/Program Files");
# path.concat("/bin"); # alternative Unix filepath
print(path.realpath); # prints "C:/Windows/Program Files" or "/usr/bin"

exists()

os.path.exists();

Returns 1 (true) if the path exists and 0 (false) if it does not.

Example

var path = os.path.new("C:/Windows");
# var path = os.path.new("/usr"); # alternative Unix filepath
print(path.exists()); # prints 1 (true)
path.set("C:/Window");
# path.set("/r"); # alternative Unix filepath
print(path.exists()); # prints 0 (false)

canRead()

os.path.canRead();

Returns 1 (true) if the path can be read (from Nasal) and 0 (false) if it cannot. This follows the rules for allowed paths.

Example

var path = os.path.new("C:/Windows");
# var path = os.path.new("/usr"); # alternative Unix filepath
print(path.canRead()); # prints 0 (false)
path.set(getprop("sim/fg-home"));
print(path.canRead()); # prints 1 (true)

canWrite()

os.path.canWrite();

Returns 1 (true) if the path can be written to (from Nasal) and 0 (false) if it cannot. This follows the rules for allowed paths.

Example

var path = os.path.new("C:/Windows");
# var path = os.path.new("/usr"); # alternative Unix filepath
print(path.canWrite()); # prints 0 (false)
path.set(getprop("sim/fg-home") ~ "/txt.log");
print(path.canWrite()); # prints 1 (true)

isFile()

os.path.isFile();

Returns 1 (true) if the path points to a file and 0 (false) if it points to a directory. Note that the path must also exist.

Example

var path = os.path.new(getprop("sim/fg-root"));
print(path.isFile()); # prints 0 (false)
path.append("Nasal/io.nas");
print(path.isFile()); # prints 1 (true)

isDir()

os.path.isDir();

Returns 1 (true) if the path points to a directory and 0 (false) if it points to a file. Note that the path must also exist.

Example

var path = os.path.new(getprop("sim/fg-root"));
print(path.isDir()); # prints 1 (true)
path.append("Nasal/io.nas");
print(path.isDir()); # prints 0 (false)

isRelative()

os.path.isRelative();

Returns 1 (true) if the path is relative and 0 (false) if it is not.

Example

var path = os.path.new(getprop("sim/fg-root"));
path.set("./Nasal");
print(path.isRelative()); # prints 1 (true)

isAbsolute()

os.path.isAbsolute();

Returns 1 (true) if the path is an absolute path and 0 (false) if it is not.

Example

var path = os.path.new(getprop("sim/fg-root"));
print(path.isAbsolute()); # prints 1 (true)

isNull()

os.path.isNull();

Returns 1 (true) if the path is null and 0 (false) if it is not.

Example

var path = os.path.new();
print(path.isNull());

create_dir()

os.path.create_dir();

Creates the parent of the path as a directory. This will only work if the path is absolute and considered as writable by fgValidatePath() (typically okay under $FG_HOME/Export).

Example

var path = os.path.new(getprop("/sim/fg-home") ~ "/Export/test/demo.txt");
path.create_dir(); # Creates $FG_HOME/Export/test/

remove()

os.path.remove();

Removes the last element of the path from the file directory. This will only work if the path is absolute and deletion of the file is permitted by the file permissions (typically okay under $FG_HOME/Export). Note that on Windows, deletion of read-only files are never permitted.

Examples

var path = os.path.new(getprop("/sim/fg-home") ~ "/Export/demo.txt");
var file = io.open(path.realpath, "w");
io.write(file, 'Hello, World' ~ "\n");
io.close(file);
print(path.exists()); # prints "1"

path.remove();
print(path.exists()); # prints "0"
var path = os.path.new(getprop("/sim/fg-home") ~ "/Export/test");
path.create_dir();
path.remove(); # folder "/test" is removed

rename()

os.path.rename(new_name);

Renames the last element of the path from the file directory. This will only work if the path is absolute, the old path is both readable and writable, the new path is writable.

Example

var path = os.path.new(getprop("/sim/fg-home") ~ "/Export/demo.txt");
var file = io.open(path.realpath, "w");
io.write(file, 'Hello, World' ~ "\n");
io.close(file);
path.rename(getprop("/sim/fg-home") ~ "/Export/demo1.txt");
print(path.realpath); # prints $FG_HOME/Export/demo1.txt

realpath

os.path.realpath;

A string variable that gives the full file path. This should only be used when the path is an absolute path. If the path is relative, it will simply be appended to the FlightGear folder (the level up from $FG_ROOT).

Example

var path = os.path.new(getprop("/sim/fg-home"));
print(path.realpath); # prints the absolute path of $FG_HOME

file

os.path.file;

A string variable that gives the last part of the filepath.

Example

var path = os.path.new(getprop("/sim/fg-home"));
print(path.file); # prints "flightgear.org"

dir

os.path.dir;

A string variable that gives all of the filepath except the last element (see os.path.file above).

Example

var path = os.path.new("Program Files/temp/text.txt");
print(path.dir); # prints "Program Files/temp"

base

os.path.base;

A string variable that gives all of the filepath except the extension of the file. If the filepath points to a folder, it has the same value as realpath.

Example

var path = os.path.new("Program Files/temp/text.txt");
print(path.base); # prints "Program Files/temp/text"

file_base

os.path.file_base;

A string variable that gives the file name without the extension. If the filepath points to a folder, it will simply be the folder name.

Example

var path = os.path.new("Program Files/temp/text.txt");
print(path.file_base); # prints "text"

extension

os.path.extension;

A string variable that gives the file's extension. If the filepath points to a folder, it will be an empty string.

Example

var path = os.path.new("Program Files/temp/text.txt");
print(path.extension); # prints "txt"

lower_extension

os.path.lower_extension;

A string variable that gives the file's extension, but converted to lowercase. If the filepath points to a folder, it will be an empty string.

Example

var path = os.path.new("Program Files/temp/text.TXT");
print(path.lower_extension); # prints "txt"

complete_lower_extension

os.path.complete_lower_extension;

This is to be used when a file has a double extension (e.g., .tar.gz). It also converts it to lowercase. If the filepath points to a folder, it will be an empty string.

Example

var path = os.path.new("Program Files/temp/text.TAR.GZ");
print(path.complete_lower_extension); # prints "tar.gz"

str

os.path.str;

A string giving the path that the instance points too. This is to be used when a file has a double extension (e.g., .tar.gz). It also converts it to lowercase. If the filepath points to a folder, it will be an empty string.

Examples

var path = os.path.new("../temp/text.txt");
print(path.str); # prints "../temp/text.txt"
var path = os.path.new(getprop("sim/fg-home"));
print(path.str); # prints the full path to $FG_HOME

mtime

os.path.mtime;

An integer giving the Unix time when the file or folder was last modified.

Example

var path = os.path.new(getprop("sim/fg-home"));
print(path.mtime); # prints a Unix time

Functions

desktop()

os.path.desktop();

Creates and returns an os.path pointing to the desktop location.

Note  As of April 2018, this function does not work properly and returns the /bin folder.

Example

var path = os.path.desktop();
print(path.realpath);

standardLocation()

os.path.standardLocation(location);

Creates and returns an os.path pointing to the standard location.

Note  As of April 2018, only supplying "HOME" to this function actually works. All the others do not work properly and return the /bin folder.
location
String specifying the standard location to use. May be one of HOME, DESKTOP, DOWNLOADS, DOCUMENTS, or PICTURES.

Example

var path = os.path.standardLocation("HOME");
print(path.realpath);