From 771d68d6ad64b24569f6c145c00f97c9acaf45a5 Mon Sep 17 00:00:00 2001 From: Tom Scheler Date: Sun, 22 Jan 2023 17:05:19 +0100 Subject: [PATCH] Add file move to FileIO --- LanguageExt.Sys/Live/FileIO.cs | 7 +++++++ LanguageExt.Sys/Sys/IO/File.cs | 11 +++++++++++ LanguageExt.Sys/Test/FileIO.cs | 4 ++++ LanguageExt.Sys/Traits/FileIO.cs | 6 ++++++ 4 files changed, 28 insertions(+) diff --git a/LanguageExt.Sys/Live/FileIO.cs b/LanguageExt.Sys/Live/FileIO.cs index 19bd02592..b7e8efe23 100644 --- a/LanguageExt.Sys/Live/FileIO.cs +++ b/LanguageExt.Sys/Live/FileIO.cs @@ -25,6 +25,13 @@ public Unit Copy(string fromPath, string toPath, bool overwrite = false) return default; } + /// + public Unit Move(string fromPath, string toPath) + { + File.Move(fromPath, toPath); + return default; + } + #if NET5PLUS /// /// Append lines to the end of a file diff --git a/LanguageExt.Sys/Sys/IO/File.cs b/LanguageExt.Sys/Sys/IO/File.cs index c925f3b83..920a03f63 100644 --- a/LanguageExt.Sys/Sys/IO/File.cs +++ b/LanguageExt.Sys/Sys/IO/File.cs @@ -33,6 +33,17 @@ public static class File public static Eff copy(string fromPath, string toPath, bool overwrite = false) => default(RT).FileEff.Map(e => e.Copy(fromPath, toPath, overwrite)); + /// + /// Move file + /// + /// Source path + /// Destination path + /// Runtime + /// Unit + [Pure, MethodImpl(AffOpt.mops)] + public static Eff move(string fromPath, string toPath) => + default(RT).FileEff.Map(e => e.Move(fromPath, toPath)); + /// /// Append lines to the end of the file provided /// diff --git a/LanguageExt.Sys/Test/FileIO.cs b/LanguageExt.Sys/Test/FileIO.cs index 2ba5f97dd..9458f218a 100644 --- a/LanguageExt.Sys/Test/FileIO.cs +++ b/LanguageExt.Sys/Test/FileIO.cs @@ -29,6 +29,10 @@ namespace LanguageExt.Sys.Test public Unit Copy(string fromPath, string toPath, bool overwrite = false) => fs.CopyFile(fromPath, toPath, overwrite, now); + /// + public Unit Move(string fromPath, string toPath) => + fs.Move(fromPath, toPath, now); + /// /// Append lines to the end of a file /// diff --git a/LanguageExt.Sys/Traits/FileIO.cs b/LanguageExt.Sys/Traits/FileIO.cs index fd2cbeec6..04fb91754 100644 --- a/LanguageExt.Sys/Traits/FileIO.cs +++ b/LanguageExt.Sys/Traits/FileIO.cs @@ -16,6 +16,12 @@ public interface FileIO /// Unit Copy(string fromPath, string toPath, bool overwrite = false); + /// + /// Move file from one place to another + /// + /// The exists or was not found. + Unit Move(string fromPath, string toPath); + /// /// Append lines to the end of a file ///