Hello,
With Android and RN 0.30 I've an issue with this module (2.0.1-rc2). Here is an example briefly : (I'll not write code, just illustrate the example).
mkdir('/tmp/a/10');
mkdir('/tmp/b/20');
So basically 2 folders with 2 folders within.
Now If I try to copyFile or moveFile like that :
moveFile('/tmp/b','/tmp/a')
I got an ENOENT: no such file or directory error
At start I just wanted to rename folder b to a but with this module I can't. Do you have any idea ?
Thanks !
I found.. (rtfm) This is just a copyFile or moveFile.
So if you want to move an entire folder you can't, you'll have to code a recursive function with readFile. I'll edit my answer soon with such a function.
Still waiting for a rename folder method by the way :)
Here it is ! Recursive move/rename functions. One drawback, you don't know when it's done.
module.exports = {
moveDirectorySafely: function(src, dst) {
RNFS.exists(dst).then((dirExists) => {
if (dirExists) {
RNFS.unlink(dst).then(() => {
this.moveDirectory(src, dst);
});
} else {
this.moveDirectory(src, dst);
}
});
},
moveDirectory: function(src, dst, root = true) {
if (root) {
src = RNFS.DocumentDirectoryPath + src;
dst = RNFS.DocumentDirectoryPath + dst;
}
RNFS.mkdir(dst).then(() => {
RNFS.readDir(src)
.then((files) => {
for (let i = 0; i < files.length; i++) {
const name = files[i].name;
const filepath = src + '/' + name;
const destpath = src.replace(src, dst);
const destfile = destpath + '/' + name;
if (files[i].isDirectory()) {
RNFS.mkdir(destfile).then(() => {
this.moveDirectory(filepath, destfile, false);
});
} else {
RNFS.copyFile(filepath, destfile);
}
}
}).catch((err) => {
console.log(err);
});
});
}
};
Most helpful comment
Here it is ! Recursive move/rename functions. One drawback, you don't know when it's done.