HomeDocs
Skip to main content

FileSystemManager.access

Introduction

Checks if a file/directory exists.

Usage Restrictions

Supported on basic library version 3.0.0 or higher.

Parameters

Object object

PropertyTypeDefault ValueRequiredDescription
pathstringYesThe file/directory path to check (relative path)
successfunctionNoCallback function executed when the interface call is successful
failfunctionNoCallback function executed when the interface call fails
completefunctionNoCallback function executed when the interface call ends (executed regardless of success or failure)

object.success Callback Function

Parameters

Object res

PropertyTypeDescription
successstringtrue - Set successfully

object.fail

Callback Function

Parameters

Object res

PropertyTypeDescription
errMsgstringError message
successstringfalse - Set failed

errMsg Description

Error MessageDescription
parameter error: F10001Invalid parameter
fail sdcard not mounted: F10002Android sdcard mount failed
fail no such file or directory: F10007, ${path}File/directory does not exist
fail operation not permitted, unlink ${filePath}The filePath provided is a directory

Sample Code

// pages/index/index.js
Page({
access() {
const fs = dlt.getFileSystemManager();
fs.access({
path: `${dlt.env.USER_DATA_PATH}/hello.txt`,
success(res) {
// File exists
console.log(res);
},
fail(res) {
// File does not exist or other errors
console.error(res);
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.