Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

io/file/move.fz


# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation.  If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
#  Tokiwa Software GmbH, Germany
#
#  Source code of Fuzion standard library feature move
#
#  Author: Wael Youssfi (wael.youssfi@tokiwa.software)
#
# -----------------------------------------------------------------------

# move -- effect wrapping the file move operation
#
public move(mop Move_Handler) : effect is

  # moves file/dir from an old path to a the new path
  # can rename the file/dir as well by changing the name of the old file/dir to a new name in the new_path
  # returns a unit type as outcome in case of success and error in case of failure
  #
  public move(
       # the old (relative or absolute) file name, using platform specific path separators
       old path,
       # the new (relative or absolute) file name, using platform specific path separators
       new path) outcome unit =>
    tmp := mop.move old new
    replace
    tmp


# the default file/dir move operation via fuzion.sys.fileio.move
#
default_move_handler : Move_Handler is
  redef move(old, new path) =>
    fuzion.sys.fileio.move old new


# shorthand for accessing move effect in current environment and performing the default move operation using
# io.file.move.move old new
# moves file/dir from an old path to a the new path
# can rename the file/dir as well by changing the name of the old file/dir to a new name in the new_path
# returns a unit type as outcome in case of success and error in case of failure
#
public move(
     # the old (relative or absolute) file name, using platform specific path separators
     old path,
     # the new (relative or absolute) file name, using platform specific path separators
     new path) outcome unit ! move =>
  (move default_move_handler).default
  move.env.move old new

# reference to the move operations that could take place
#
private:public Move_Handler ref is
    move(old path, new path) outcome unit => abstract

last changed: 2026-03-09