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) : simple_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
  #
  move(
       # the old (relative or absolute) file name, using platform specific path separators
       old_path String,
       # the new (relative or absolute) file name, using platform specific path separators
       new_path String) =>
    tmp := mop.move old_path new_path
    replace
    tmp


  # the default file/dir move operation via fuzion.sys.fileio.move
  #
  type.default_move_handler : io.file.Move_Handler is
    move(old_path String, new_path String) =>
      fuzion.sys.fileio.move old_path new_path


  # install default effect io.file.move
  #
  type.install_default =>
    (io.file.move default_move_handler).default


# short-hand for accessing move effect in current environment and performing the default move operation using
# io.file.move.move old_path new_path
# 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 String,
     # the new (relative or absolute) file name, using platform specific path separators
     new_path String) =>
  move.install_default
  move.env.move old_path new_path

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