tav-media
Version:
Cross platform media editing framework
58 lines (57 loc) • 1.16 kB
JavaScript
const fs = wx.getFileSystemManager();
export const touchDirectory = (path) => {
try {
fs.accessSync(path);
}
catch (e) {
try {
fs.mkdirSync(path);
}
catch (err) {
console.error(e);
}
}
};
export const writeFile = (path, data) => {
try {
fs.writeFileSync(path, data, 'utf8');
}
catch (e) {
throw new Error(e);
}
};
export const removeFile = (path) => {
try {
fs.accessSync(path);
fs.unlinkSync(path);
}
catch (e) {
console.error(e);
}
};
export const clearDirectory = (path) => {
try {
const res = fs.readdirSync(path);
if (res.length > 0) {
res.forEach((file) => {
fs.unlinkSync(`${path}${file}`);
});
}
return true;
}
catch (e) {
console.error(e);
return false;
}
};
export const checkFileExist = (path) => new Promise((resolve) => {
wx.getFileInfo({
filePath: path,
success() {
resolve(true);
},
fail() {
resolve(false);
},
});
});