Nasal library/os.path: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
m (→‎Class: .new: Add Unix example)
No edit summary
Line 15: Line 15:
==== new() ====
==== new() ====
{{Nasal doc
{{Nasal doc
|syntax = geo.Coord.new(path);
|syntax = os.path.new([path]);
|text = Constructor function. Returns a new <code>os.path</code> instance.
|text = Constructor function. Returns a new <code>os.path</code> instance. Note that the path must not violate the rules for allowed paths.
|param1 = path
|param1 = path
|param1text = A string pointing to a filepath.
|param1text = Optional string specifying the filepath. If not given, the path will default to [[$FG_ROOT]]
|example1 = var path = os.path.new("C:/Windows"); # A Windows filepath
|example1 = var path = os.path.new();
# var path = os.path.new("/usr/bin/"); # A Unix 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
print(path.realpath);
print(path.realpath);
}}
}}


==== set() ====
==== set() ====
{{Nasal doc
|syntax = os.path.set([path]);
|text = Sets the filepath. Note that the path must not violate the rules for allowed paths.
|param1 = path
|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");
# 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
print(path.realpath);
path.set("C:/Windows/Program Files");
# path.set("/usr/bin/"); # alternative Unix filepath
print(path.realpath); # prints new path
}}
==== append() ====
==== append() ====
==== concat() ====
==== concat() ====

Revision as of 21:09, 11 February 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 geo 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.

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

Examples

var path = os.path.new();
print(path.realpath); # will print $FGROOT
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

Examples

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
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/bin/"); # alternative Unix filepath
print(path.realpath); # prints new path

append()

concat()

exists()

canRead()

canWrite()

isFile()

isDir()

isRelative()

isAbsolute()

isNull()

create_dir()

remove()

rename()

realpath

file

dir

base

file_base

extension

lower_extension

complete_lower_extension

str

mtime

Functions

desktop()

standardLocation()