FileUtils.Move 添加 toRecycleBin

This commit is contained in:
LTCat committed 2026-09-26 01:28:01 +08:00
1 parent 8a7e33c66a
commit 36ecaf29b6
1 file changed
+5 -3
+5 -3
View File
@@ -205,8 +205,9 @@ public static class FileUtils {
/// <summary> /// <summary>
/// 剪切文件。 /// 剪切文件。
/// 会创建对应文件夹、覆盖已有的文件。 /// 会创建对应文件夹、覆盖已有的文件。
/// 若指定了 <paramref name="toRecycleBin"/>,则在覆盖前将老文件删除到回收站。
/// </summary> /// </summary>
public static void Move(string sourceFilePath, string destFilePath) { public static void Move(string sourceFilePath, string destFilePath, bool toRecycleBin = false) {
sourceFilePath = PathUtils.ForCompare(sourceFilePath); sourceFilePath = PathUtils.ForCompare(sourceFilePath);
destFilePath = PathUtils.ForCompare(destFilePath); destFilePath = PathUtils.ForCompare(destFilePath);
if (string.CompareOrdinal(sourceFilePath, destFilePath) == 0) { if (string.CompareOrdinal(sourceFilePath, destFilePath) == 0) {
@@ -225,7 +226,7 @@ public static class FileUtils {
} else { } else {
// 实际的剪切 // 实际的剪切
DirectoryUtils.Create(PathUtils.RemoveLastPart(destFilePath)); DirectoryUtils.Create(PathUtils.RemoveLastPart(destFilePath));
FileUtils.Delete(destFilePath); FileUtils.Delete(destFilePath, toRecycleBin);
Logger.Trace($"剪切文件:{sourceFilePath} → {destFilePath}"); Logger.Trace($"剪切文件:{sourceFilePath} → {destFilePath}");
Retrier.Attempt(delay: _ => TimeSpan.FromMilliseconds(200), isRetryAllowed: ex => ex is IOException, action: _ => { Retrier.Attempt(delay: _ => TimeSpan.FromMilliseconds(200), isRetryAllowed: ex => ex is IOException, action: _ => {
FileUtils.SetReadOnly(sourceFilePath, false); FileUtils.SetReadOnly(sourceFilePath, false);
@@ -510,7 +511,8 @@ public class FileChecker {
/// 是否要求为 JSON 文件。 /// 是否要求为 JSON 文件。
/// </summary> /// </summary>
public bool IsJson = false; public bool IsJson = false;
// TODO: 重构此函数,使它变成 void,并抛出异常
/// <summary> /// <summary>
/// 检查文件。 /// 检查文件。
/// <para/>若成功则返回 <c>null</c>,失败则返回错误的描述文本(文本不以句号结尾)。 /// <para/>若成功则返回 <c>null</c>,失败则返回错误的描述文本(文本不以句号结尾)。