Rename a file: Difference between revisions

Content added Content deleted
(Add Mercury.)
Line 534:
-- Root
renameFile "/input.txt" "/output.txt"</lang>
 
=={{header|Mercury}}==
<lang mercury>:- module rename_file.
:- interface.
 
:- import_module io.
:- pred main(io::di, io::uo) is det.
 
:- implementation.
 
:- import_module dir.
 
main(!IO) :-
rename_file("input.txt", "output.txt", !IO),
rename_file("docs", "mydocs", !IO),
rename_file("/input.txt", "/output.txt", !IO),
rename_file("/docs", "/mydocs", !IO).
 
:- pred rename_file(string::in, string::in, io::di, io::uo) is det.
 
rename_file(OldName, NewName, !IO) :-
io.rename_file(OldName, NewName, Result, !IO),
(
Result = ok
;
Result = error(Error),
print_io_error(Error, !IO)
).
 
:- pred print_io_error(io.error::in, io::di, io::uo) is det.
 
print_io_error(Error, !IO) :-
io.stderr_stream(Stderr, !IO),
io.write_string(Stderr, io.error_message(Error), !IO),
io.nl(Stderr, !IO),
io.set_exit_status(1, !IO).</lang>
 
=={{header|MUMPS}}==
<p>ANSI MUMPS doesn't allow access to the operating system except possibly through the View command and $View function, both of which are implementation specific. Intersystems' Caché does allow you to create processes with the $ZF function, and if the permissions for the Caché process allow it you can perform operating system commands.</p>