Nasal library/os.path: Difference between revisions

More doc
m (→‎realpath: finish)
(More doc)
Line 169: Line 169:
{{Nasal doc
{{Nasal doc
|syntax = os.path.realpath;
|syntax = os.path.realpath;
|text = A variable that is a string and 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]]).
|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"));
|example1 = var path = os.path.new(getprop("/sim/fg-home"));
print(path.realpath); # prints the absolute path of $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 ====
==== mtime ====
==== mtime ====