From 46d40620496ae1ca9d585da22df59a1db29cbc92 Mon Sep 17 00:00:00 2001 From: laolarou Date: Wed, 4 Dec 2024 11:45:03 +0800 Subject: [PATCH] Update FileHelper.cs --- .../ProjBobcat/Class/Helper/FileHelper.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ProjBobcat/ProjBobcat/Class/Helper/FileHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/FileHelper.cs index 5586dd6..bba604d 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/FileHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/FileHelper.cs @@ -42,4 +42,22 @@ public static bool DeleteFileWithRetry(string filePath, int retryCount = 3) return false; } + + public static bool MoveFileWithRetry(string oldPath, string newPath, int retryCount = 3) + { + ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(retryCount, 0); + + for (var i = 0; i < retryCount; i++) + try + { + File.Move(oldPath, newPath); + return true; + } + catch + { + // ignored + } + + return false; + } } \ No newline at end of file