文件操作
所有路径均为相对于 SDK 文件存储目录的相对路径
fileExists(path)
Section titled “fileExists(path)”检查文件或目录是否存在。
const info = await SuperSDK.fileExists('downloads/file.zip');console.log(info);// { exists: true, isFile: true, isDirectory: false }返回值:
| 参数 | 类型 | 说明 |
|---|---|---|
| exists | boolean | 是否存在 |
| isFile | boolean | 是否为文件 |
| isDirectory | boolean | 是否为目录 |
getFileMd5(path)
Section titled “getFileMd5(path)”获取文件的 MD5 值。
const { md5 } = await SuperSDK.getFileMd5('downloads/file.zip');console.log('MD5:', md5);deleteFile(path)
Section titled “deleteFile(path)”删除文件或目录(递归删除)。
await SuperSDK.deleteFile('downloads/old_file.zip');moveFile(srcPath, destPath)
Section titled “moveFile(srcPath, destPath)”移动或重命名文件。
await SuperSDK.moveFile('downloads/temp.zip', 'cache/final.zip');createDir(path)
Section titled “createDir(path)”创建目录(支持递归创建)。
await SuperSDK.createDir('data/cache/images');如果目录已存在,不会报错。
listDir(path)
Section titled “listDir(path)”列出目录内容。
const { files } = await SuperSDK.listDir('downloads');files.forEach(file => { console.log(file.name, file.isFile ? '文件' : '目录', file.size);});返回值 files 数组元素:
| 参数 | 类型 | 说明 |
|---|---|---|
| name | string | 文件名 |
| isFile | boolean | 是否为文件 |
| isDirectory | boolean | 是否为目录 |
| size | number | 文件大小(字节) |
| lastModified | number | 最后修改时间(时间戳) |
readFile(path)
Section titled “readFile(path)”读取文本文件内容。
const { content } = await SuperSDK.readFile('config/settings.json');const settings = JSON.parse(content);writeFile(path, content)
Section titled “writeFile(path, content)”写入文本文件内容。
const settings = { theme: 'dark', lang: 'zh' };await SuperSDK.writeFile('config/settings.json', JSON.stringify(settings));