Skip to main content

spo file rename

Renames a file

Usage

m365 spo file rename [options]

Options

-u, --webUrl <webUrl>

The URL of the site where the file is located.

-s, --sourceUrl <sourceUrl>

The server- or site-relative decoded URL of the file to rename.

-t, --targetFileName <targetFileName>

New file name of the file.

--force

If a file already exists with target file name, it will be moved to the recycle bin. If omitted, the rename operation will be canceled if a file already exists with the specified file name.

-h, --help [help]

Output usage information. Optionally, specify which section of command's help you want to see. Allowed values are options, examples, remarks, response, full. Default is options.

--query [query]

JMESPath query string. See http://jmespath.org/ for more information and examples.

-o, --output [output]

Output type. json, text, csv, md, none. Default json.

--verbose

Runs command with verbose logging.

--debug

Runs command with debug logging.

Remarks

If you try to rename a file without the --force flag and a file with this name already exists, the operation will be cancelled.

Examples

Renames a file.

m365 spo file rename --webUrl https://contoso.sharepoint.com/sites/project-x --sourceUrl '/Shared Documents/Test1.docx' --targetFileName 'Test2.docx'

Renames a file. If the file with the target file name already exists, this file will be moved to the recycle bin.

m365 spo file rename --webUrl https://contoso.sharepoint.com/sites/project-x --sourceUrl '/Shared Documents/Test1.docx' --targetFileName 'Test2.docx' --force

Response

[
{
"ErrorCode": 0,
"ErrorMessage": null,
"FieldName": "FileLeafRef",
"FieldValue": "Newlogo2.jpg",
"HasException": false,
"ItemId": 26
}
]
CTRL + M