【发布时间】:2020-06-23 16:15:43
【问题描述】:
我在重命名和移动文件夹时遇到问题,因为 react native fs 只有 moveFile 选项,它只对文件而不是文件夹执行。递归执行也很麻烦,并且由于同步,在执行重命名或移动选项后很难执行行执行。我在下面附上了移动代码和错误。请帮我解决这个问题。
moveAll = (path, outputPath) => new Promise((resolve, reject) => {
// is a folder
if (path.split(".").length == 1) {
// CHeck if folder already exists
RNFS.exists(outputPath)
.then((exists) => {
if (exists) {
// Delete the folder if exists
RNFS.unlink(outputPath)
.then(() => {
})
// `unlink` will throw an error, if the item to unlink does not exist
.catch((err) => {
console.log(err.message);
});
}
// MAKE FRESH FOLDER
RNFS.mkdir(outputPath);
resolve(RNFS.readDir(path)
.then((result) => {
result.map(
(item) =>
new Promise((resolve, reject) => {
resolve(this.moveAll(item.path, outputPath + "/" + item.name));
})
)
})
.catch((e) => {
console.log("ERROR", e)
})
)
})
.catch((e) => {
console.log(e)
})
} else {
RNFS.moveFile(path, outputPath)
.then(() => {
})
.catch((e) => {
console.log(e)
})
}
})
提前致谢:)
【问题讨论】:
标签: javascript android react-native filesystems react-native-fs