Nasal library/os.path: Difference between revisions

Doc rename()
(Doc remove())
(Doc rename())
Line 145: Line 145:
|example1 = var path = os.path.new(getprop("/sim/fg-home") ~ "/Export/demo.txt");
|example1 = var path = os.path.new(getprop("/sim/fg-home") ~ "/Export/demo.txt");
var file = io.open(path.realpath, "w");
var file = io.open(path.realpath, "w");
io.write(file, 'Hello, World' ~ "/n");
io.write(file, 'Hello, World' ~ "\n");
io.close(file);
io.close(file);
print(path.exists()); # prints "1"
print(path.exists()); # prints "1"
Line 156: Line 156:
}}
}}
==== 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 ====
==== file ====
==== file ====