File operations
All paths are relative paths relative to the SDK file storage directory.
fileExists(path)
Section titled “fileExists(path)”Check if the file or directory exists.
const info = await SuperSDK.fileExists('downloads/file.zip');console.log(info);// { exists: true, isFile: true, isDirectory: false }Return Value:
| Parameter | Type | Description |
|---|---|---|
| exists | boolean | Does it exist? |
| isFile | boolean | Is it a file? |
| isDirectory | boolean | Is it a directory? |
getFileMd5(path)
Section titled “getFileMd5(path)”Get the MD5 value of the file.
const { md5 } = await SuperSDK.getFileMd5('downloads/file.zip');console.log('MD5:', md5);deleteFile(path)
Section titled “deleteFile(path)”Delete files or directories (recursive deletion).
await SuperSDK.deleteFile('downloads/old_file.zip');moveFile(srcPath, destPath)
Section titled “moveFile(srcPath, destPath)”Move or rename files.
await SuperSDK.moveFile('downloads/temp.zip', 'cache/final.zip');createDir(path)
Section titled “createDir(path)”Create directory (supports recursive creation).
await SuperSDK.createDir('data/cache/images');If the directory already exists, no error will be reported.
listDir(path)
Section titled “listDir(path)”List directory contents.
const { files } = await SuperSDK.listDir('downloads');files.forEach(file => { console.log(file.name, file.isFile ? 'file' : 'directory', file.size);});Return value files array elements:
| Parameter | Type | Description |
|---|---|---|
| name | string | File name |
| isFile | boolean | Is it a file? |
| isDirectory | boolean | Is it a directory? |
| size | number | File size (bytes) |
| lastModified | number | Last modified time (timestamp) |
readFile(path)
Section titled “readFile(path)”Read the text file content.
const { content } = await SuperSDK.readFile('config/settings.json');const settings = JSON.parse(content);writeFile(path, content)
Section titled “writeFile(path, content)”Write text file content.
const settings = { theme: 'dark', lang: 'zh' };await SuperSDK.writeFile('config/settings.json', JSON.stringify(settings));