Nasal library/os.path: Difference between revisions

Jump to navigation Jump to search
→‎Class: Doc concat()
(Doc append())
(→‎Class: Doc concat())
Line 19: Line 19:
|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);
Line 33: Line 31:
|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 50: Line 43:
|text = Appends a new part to the filepath.
|text = Appends a new part to the filepath.
|param1 = path
|param1 = path
|param1text = Optional string specifying the filepath. If not given, the resultant path will not change.
|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");
|example1 = var path = os.path.new("C:/Windows");
# var path = os.path.new("/usr/"); # alternative Unix filepath
print(path.realpath);
path.append();
print(path.realpath); # the path will not change
|example2 = var path = os.path.new("C:/Windows");
# var path = os.path.new("/usr/"); # alternative Unix filepath
# var path = os.path.new("/usr/"); # alternative Unix filepath
print(path.realpath);
print(path.realpath);
path.append("Program Files");
path.append("Program Files");
# path.set("bin"); # alternative Unix filepath
# path.append("bin"); # alternative Unix filepath
print(path.realpath); # prints "C:/Windows/Program Files" or "/usr/bin"
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() ====
==== canRead() ====
==== canRead() ====

Navigation menu