HomeDocs
Skip to main content

FileSystemManager.rename

Introduction

This function is used to rename a file. It can move a file from the oldPath to the newPath.

Usage Restrictions

This feature is supported in Basic Library version 3.0.0 or higher.

Parameters

Object object

AttributeTypeDefault ValueRequiredDescription
oldPathstringYesSource file path, supports relative paths
newPathstringYesNew file path, supports local paths
successfunctionNoCallback function when the API call is successful
failfunctionNoCallback function when the API call fails
completefunctionNoCallback function when the API call ends (executed regardless of success or failure)

object.success

Callback Function

Parameters

Object res

AttributeTypeDescription
successstringtrue - success

object.fail

Callback Function

Parameters

Object res

AttributeTypeDescription
errMsgstringError message
successstringfalse - failure

errMsg Description

Error messageDescription
parameter error: F10001Invalid parameter
fail sdcard not mounted: F10002Android sdcard mounting failed
fail permission denied: F10005, rename ${oldPath} -> ${newPath}Source file or target file does not have write permission
fail no such file or directory: F10007, rename ${oldPath} -> ${newPath}Source file does not exist or the parent directory of the target file path does not exist

Sample Code

// pages/index/index.js
Page({
rename() {
const fs = dlt.getFileSystemManager();
fs.rename({
oldPath: `${dlt.env.USER_DATA_PATH}/hello.txt`,
newPath: `${dlt.env.USER_DATA_PATH}/hello_new.txt`,
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.