1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Merge pull request #2052 from Booklordofthedings/master

Add Directory.Copy to corlib
This commit is contained in:
Brian Fiete 2024-10-30 07:08:09 -04:00 committed by GitHub
commit 8313fdf2d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -90,6 +90,23 @@ namespace System.IO
return .Ok;
}
///Copies and overwrites the contents of fromPath into toPath.
public static Result<void, Platform.BfpFileResult> 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) =>