Availability:built-in
rename_file(+File1,
+File2)Rename File1 as File2. The semantics is compatible
to the semantics of the POSIX rename() system call as far as the
operating system allows. Notably, if File2 exists, the
operation succeeds (except for possible permission errors) and is atomic
(meaning there is no window where File2 does not exist). Note
that
File2 cannot be an existing directory.159The
POSIX semantics describe one exception: a directory can be moved to an
existing empty directory. To move a file to
another directory one must create File2 from the target
directory and the base name of File1. See file_base_name/2.
The rename() system call has a large number of error
conditions. Errors are mapped to Prolog exceptions using a generic
conversion based on the
File1 argument. As a result, the errors may be confusing.
Future versions may improve on this.