Expand/Shrink

move_file

Definition: bool res = move_file(string src, string dest, bool overwrite=false)
Description: Move a file to another location.

src: the name of the file or directory to move.
dest: the new location for the file.
overwrite: false (0/the default) to abandon the operation if the destination file already exists, or true (1) to delete and replace any existing destination file.

Returns: false (0) on failure, true (1) on success.
pwa/p2js: Not supported.
Comments: If dest does not contain a full path specification, current_dir() will be used, rather than starting from/relative to the source directory.

Unlike some other routines here, any path separators should be appropriate for the operating system, namely backslash ('\\') on Windows and forwardslash ('/') on Linux.
If in doubt (not already a result from the top half of the table) pass src/dest through get_proper_path() and/or get_proper_dir() before passing them to this routine.

For best results, use fully qualified absolute pathnames. You should not rely on relative paths in dest any more than you do in src; for instance move_file(`demo\test`,`demo\test2`) is fine, whereas move_file(`demo\test`,"test2") is likely to move it up a directory, and move_file(`C:\Program Files (x86)\Phix\demo\test`,"test2") is likely to move it to the current directory. The precise behaviour of path-less operations is operating system dependent.

If overwrite was requested but the move fails, there is no guarantee that any existing destination file is preserved, deleted, corrupted, or all three.

The use of a named parameter when setting the overwrite flag is recommended, to make the intent clear and the code easier to read.
Implementation: See builtins\pfile.e (an autoinclude) for details of the actual implementation.
See Also: rename_file, copy_file