From 63d5bc07b5a3a27b392f18b45e11e50a02d0944e Mon Sep 17 00:00:00 2001 From: Jannis Date: Tue, 29 Oct 2024 22:37:38 +0000 Subject: [PATCH] Add Directory.Copy --- BeefLibs/corlib/src/IO/Directory.bf | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/BeefLibs/corlib/src/IO/Directory.bf b/BeefLibs/corlib/src/IO/Directory.bf index 232669bf..94813e0d 100644 --- a/BeefLibs/corlib/src/IO/Directory.bf +++ b/BeefLibs/corlib/src/IO/Directory.bf @@ -90,6 +90,23 @@ namespace System.IO return .Ok; } + ///Copies and overwrites the contents of fromPath into toPath. + public static Result Copy(StringView fromPath, StringView toPath) + { + if(Directory.CreateDirectory(toPath) case .Err(let err)) + return .Err(err); + + for(var file in Directory.EnumerateFiles(fromPath)) + if(File.Copy(file.GetFilePath(.. scope .()), scope $"{toPath}/{file.GetFileName(.. scope .())}") case .Err(let err)) + return .Err(err); + + for(var dir in Directory.EnumerateDirectories(fromPath)) + if(Directory.Copy(dir.GetFilePath(.. scope .()), scope $"{toPath}/{dir.GetFileName(.. scope .())}") case .Err(let err)) + return .Err(err); + + return .Ok; + } + public static void GetCurrentDirectory(String outPath) { Platform.GetStrHelper(outPath, scope (outPtr, outSize, outResult) =>