HomeDocs
Skip to main content

FileSystemManager.copyFile

Introduction

Copies a file.

Usage Restrictions

Requires basic library version 3.0.0 or higher.

Parameters

Object object

PropertyTypeDefaultRequiredDescription
srcPathstringYesSource file path (relative path)
destPathstringYesDestination file path (relative path)
successfunctionNoCallback function for successful API call
failfunctionNoCallback function for failed API call
completefunctionNoCallback function called after API call completion (executed regardless of success or failure)

object.success Callback Function

Parameters

Object res

PropertyTypeDescription
successstringtrue-Successful

object.fail Callback Function

Parameters

Object res

PropertyTypeDescription
errMsgstringError message
successstringfalse-Failed

errMsg Description

Error messageExplanation
parameter error: F10001Source path or destination path parameter is null
fail sdcard not mounted: F10002Android sdcard mount failed
fail the maximum size of the file storage limit exceeded: F10004Insufficient storage space
fail permission denied: F10005, copyFile ${srcPath} -> ${destPath}Copy failed, specified destination file path does not have write permission
fail no such file or directory: F10007, copyFile ${srcPath} -> ${destPath}Source file does not exist, or the parent directory of the destination file path does not exist

Sample Code

// pages/index/index.js
Page({
copyFile() {
const fs = dlt.getFileSystemManager();
fs.copyFile({
srcPath: `${dlt.env.USER_DATA_PATH}/hello.txt`,
destPath: `${dlt.env.USER_DATA_PATH}/hello_copy.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.