Hi,
Is there a way to delete all files within a temp directory? I know I can access the directory with RNFS.TemporaryDirectoryPath but instead of adding a ref to a single file I'd like to remove all files contained within.
The way to do that right now is, like you already mentioned, looping over the contents and removing each file on its own.
@johanneslumpe How would you do that?
@cvarley100 If you haven't figured this out yet, you could just read the files at a directory readdir(<dir path>) and then do an unlink on each file in the result paths.forEach(p => unlink(p)).
However, you shouldn't need to do this. The documentation says unlink can recursively delete directories. Just feed it the directory you want to remove: unlink(<dir path>)
How do I delete files with same extension?
I've tried
RNFS.unlink(RNFS.DocumentDirectoryPath+'/*.jpg').then(()=>{
console.log('finish delete');
});
Not working
Is there any better way to do this now ? Or do we still need to iterate over and delete each file ?
@Udbhav12 This works for me: RNFS.unlink(/path/to/dir/). This deletes the whole directory. After this, you can create the directory again using RNFS.mkdir
@ashar-7 Do you know if RNFS.unlink is working on Android 10 ?
thanks
@ashar-7 Do you know if RNFS.unlink is working on Android 10 ?
Nope I haven't used react since a year
Most helpful comment
@cvarley100 If you haven't figured this out yet, you could just read the files at a directory
readdir(<dir path>)and then do an unlink on each file in the resultpaths.forEach(p => unlink(p)).However, you shouldn't need to do this. The documentation says
unlinkcan recursively delete directories. Just feed it the directory you want to remove:unlink(<dir path>)