lang • move

MOVE

MOVE OldName TO NewName

Renames or moves a file or a directory.

Oldname and NewName can be located on different directories, but must be located on the same device.

If you want to move a file whatever its location is, do the following:

TRY MOVE OldName TO NewName
IF ERROR THEN
  TRY COPY OldName TO NewName
  IF NOT ERROR THEN KILL OldName
ENDIF

MOVE ... KILL

MOVE OldName KILL NewName MOVE OldName DOWNTO NewName

Since 3.11

Renames or moves a file or a directory, erasing the destination file first, the two operations being atomic.

Oldname and NewName can be located on different directories, but must be located on the same device.

This is the function you must use when you are saving a file, but you don't want to see a corrupted saved file on the disk if you have a crash:

  • Save the new file to a temporary path located in the same directory as the old file.

  • Put your process identifier in the temporary path, if several instances of your program want to write the file at the same time.

  • Once the file has been saved, use MOVE KILL to replace the old file by the new one atomically.

That way, if you have a crash, either you have the new file, either you still have the old file, with eventually a piece of the temporary file being saved.

MOVE ... DOWNTO ... is a deprecated syntax introduced in Gambas 3.10.

See also