Skip to content

[Enhancement]: Extend spo file copy with nameConflictBehavior option #3911

@milanholemans

Description

@milanholemans

Context

Originating from #3906

Currently it is impossible to copy a file to the same folder, or to another folder where a file with the same name is stored. The command will throw an error Error: A file or folder with the name 'sample.pdf' already exists at the destination.

We could add a new option --nameConflictBehavior [nameConflictBehavior] to let the user choose what to do on a naming conflict.
There are 3 possible values:

  • Fail
  • Replace
  • Rename

In the latter case, the copied document will get a number postfix that is available e.g. Document1.docx, if that one is already taken, Document2.docx etc.

Options to add

Option Description
--nameConflictBehavior [nameConflictBehavior] Behavior when a document with the same name is already present at the destination. Possible values: fail, replace, rename. Default is fail.

Technical side

We could add an extra property to the existing call:

POST https://contoso.sharepoint.com/sites/project/_api/site/CreateCopyJobs
{
  NameConflictBehavior: 0
}

NameConflictBehavior values

Label Value
Fail 0
Replace 1
Rename 2

Extra

Currently we have an option --deleteIfAlreadyExists. Maybe we could replace the logic of this option with the --nameConflictBehavior replace option. However in that case the file will be overwritten instead of being recycled, maybe that's not ideal.

Update

TL;DR

Agreed to do the following actions:

  • Use the new API endpoint SP.MoveCopyUtil since this gives us more flexibility and no file size limits
  • Remove option --deleteIfAlreadyExists and --allowSchemaMismatch
  • Add option --nameConflictBehavior [nameConflictBehavior] with options fail, replace, rename.
  • Add option --bypassSharedLock
  • Add option --newName [newName]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions