From cb1e3ec49f88cde9aeac33d9c64972091dab8128 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 30 Oct 2024 07:26:29 -0400 Subject: [PATCH] Copy fixup --- BeefLibs/corlib/src/IO/Directory.bf | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/BeefLibs/corlib/src/IO/Directory.bf b/BeefLibs/corlib/src/IO/Directory.bf index 94813e0d..7a4abb6e 100644 --- a/BeefLibs/corlib/src/IO/Directory.bf +++ b/BeefLibs/corlib/src/IO/Directory.bf @@ -90,20 +90,14 @@ namespace System.IO return .Ok; } - ///Copies and overwrites the contents of fromPath into toPath. + /// 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); - + Try!(Directory.CreateDirectory(toPath)); + for (var file in Directory.EnumerateFiles(fromPath)) + Try!(File.Copy(file.GetFilePath(.. scope .()), file.GetFileName(.. scope $"{toPath}/"))); + for (var dir in Directory.EnumerateDirectories(fromPath)) + Try!(Directory.Copy(dir.GetFilePath(.. scope .()), dir.GetFileName(.. scope $"{toPath}/"))); return .Ok; }