From 832ddf144215291785b079735dcd868d86e4e683 Mon Sep 17 00:00:00 2001 From: Glax Date: Sat, 8 Mar 2025 18:35:41 +0100 Subject: [PATCH] Implement MoveFileOrFolderJob.cs --- API/Schema/Jobs/MoveFileOrFolderJob.cs | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/API/Schema/Jobs/MoveFileOrFolderJob.cs b/API/Schema/Jobs/MoveFileOrFolderJob.cs index 956dd7c..02ecf3d 100644 --- a/API/Schema/Jobs/MoveFileOrFolderJob.cs +++ b/API/Schema/Jobs/MoveFileOrFolderJob.cs @@ -8,6 +8,33 @@ public class MoveFileOrFolderJob(string fromLocation, string toLocation, string? protected override IEnumerable RunInternal(PgsqlContext context) { - throw new NotImplementedException(); + try + { + FileInfo fi = new FileInfo(FromLocation); + if (!fi.Exists) + return []; + if (File.Exists(ToLocation))//Do not override existing + return []; + if(fi.Attributes.HasFlag(FileAttributes.Directory)) + MoveDirectory(fi, ToLocation); + else + MoveFile(fi, ToLocation); + } + catch (Exception e) + { + + } + + return []; + } + + private void MoveDirectory(FileInfo from, string toLocation) + { + Directory.Move(from.FullName, toLocation); + } + + private void MoveFile(FileInfo from, string toLocation) + { + File.Move(from.FullName, toLocation); } } \ No newline at end of file