From 2db018c54b718c7d09f7d3a6329c58f1f5d3116a Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Tue, 4 Apr 2023 23:17:47 +0600 Subject: [PATCH] Directory/File .Move --- DTLib/DTLib.csproj | 2 +- DTLib/Filesystem/Directory.cs | 11 +++++++++++ DTLib/Filesystem/File.cs | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/DTLib/DTLib.csproj b/DTLib/DTLib.csproj index 53e7446..c81ab69 100644 --- a/DTLib/DTLib.csproj +++ b/DTLib/DTLib.csproj @@ -2,7 +2,7 @@ DTLib - 1.2.0 + 1.2.1 Timerix Library for all my C# projects GIT diff --git a/DTLib/Filesystem/Directory.cs b/DTLib/Filesystem/Directory.cs index 06dae54..1c5cdb2 100644 --- a/DTLib/Filesystem/Directory.cs +++ b/DTLib/Filesystem/Directory.cs @@ -46,6 +46,17 @@ public static class Directory } } + public static void Move(IOPath current_path, IOPath target_path, bool overwrite) + { + if (Exists(target_path)) + { + if (overwrite) + Delete(target_path); + else throw new Exception($"directory {target_path} already exists"); + } + System.IO.Directory.Move(current_path.Str, target_path.Str); + } + /// удаляет папку со всеми подпапками и файлами public static void Delete(IOPath dir) => System.IO.Directory.Delete(dir.Str, true); diff --git a/DTLib/Filesystem/File.cs b/DTLib/Filesystem/File.cs index 6c2d118..04f7953 100644 --- a/DTLib/Filesystem/File.cs +++ b/DTLib/Filesystem/File.cs @@ -37,6 +37,17 @@ public static class File newFile.Close(); } + public static void Move(IOPath current_path, IOPath target_path, bool overwrite) + { + if (Exists(target_path)) + { + if (overwrite) + Delete(target_path); + else throw new Exception($"file {target_path} already exists"); + } + System.IO.File.Move(current_path.Str, target_path.Str); + } + public static void Delete(IOPath file) => System.IO.File.Delete(file.Str); public static byte[] ReadAllBytes(IOPath file)