📌 从基础库 3.125.4 版本开始支持
删除指定文件
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
filePath | string | 是 | 要删除的文件路径(本地路径) | |
success | function | 否 | 删除成功的回调函数 | |
fail | function | 否 | 删除失败的回调函数 | |
complete | function | 否 | 调用结束的回调函数 |
const fs = xhs.getFileSystemManager(); // 异步删除 fs.unlink({ filePath: `${xhs.env.USER_DATA_PATH}/hello.txt`, success() { console.log('文件删除成功'); }, fail(res) { console.error('删除失败:', res.errMsg); } }); // 同步删除 try { fs.unlinkSync(`${xhs.env.USER_DATA_PATH}/hello.txt`); console.log('同步删除成功'); } catch(e) { console.error('同步删除失败:', e.errMsg || e); }