Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Files.App/Utils/Storage/Operations/FileOperationsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,15 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
if (!SafetyExtensions.IgnoreExceptions(() =>
{
using var shi = new ShellItem(fileToRenamePath);
op.QueueRenameOperation(shi, newName);

// Generate an incremental name (e.g. "file (2).txt") instead of letting the shell append a localized "Copy" suffix.
// A case-only rename targets the same item, so it must be left untouched.
var renameTargetPath = Path.Combine(Path.GetDirectoryName(fileToRenamePath) ?? string.Empty, newName);
var finalName = !overwriteOnRename && !string.Equals(fileToRenamePath, renameTargetPath, StringComparison.OrdinalIgnoreCase)
? GetIncrementalName(false, renameTargetPath, fileToRenamePath)
: newName;

op.QueueRenameOperation(shi, finalName);
}))
{
shellOperationResult.Items.Add(new ShellOperationItemResult()
Expand Down Expand Up @@ -449,7 +457,9 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
?? throw new ArgumentException("The move destination must include a parent folder.", nameof(moveDestination));
using ShellFolder shd = new(destinationFolderPath);

op.QueueMoveOperation(shi, shd, Path.GetFileName(moveDestination[i]));
// Generate an incremental name (e.g. "file (2).txt") instead of letting the shell append a localized "Copy" suffix
var moveFileName = GetIncrementalName(overwriteOnMove, moveDestination[i], fileToMovePath[i]);
op.QueueMoveOperation(shi, shd, moveFileName);
}))
{
shellOperationResult.Items.Add(new ShellOperationItemResult()
Expand Down