2

I'm trying to delete some files from the Android Download Directory. I got the android permission to the external storage to do it, so this is my code :

var RNFS = require('react-native-fs');

...

await RNFS.exists(filepath).then((exists) => {
  if (exists) {
      RNFS.unlink(filepath).then(() => {
         RNFS.scanFile(filepath);
      })
   }
});

The unlink function works perfectly when I add some log in it. It doesn't catch(), but when I launch the same script again, the unlink still works while the file must be deleted, how is it possible ??

I don't understand what I have to do to completely delete these files...

EDIT :

I've checked the react-native-fs and it says :

Android support is currently limited to only the DocumentDirectory. This maps to the app's files directory.

So how can I delete files in the Download directory ?

Thibault Dumas
  • 1,060
  • 2
  • 10
  • 21
  • did you try console logging the file path, are you sure you are passing the same file path? – senthil balaji Sep 28 '20 at 08:59
  • exactly the same, and the file is found every time. – Thibault Dumas Sep 28 '20 at 09:16
  • Did you find any solution?? – Abhishek Jaiswal Nov 21 '21 at 13:38
  • There has to be mistake on your end or the package has been updated since you wrote your question, because I just tested this and results are: ---- if file exists, it is deleted either from app dir or download dir. ---- if file doesn't exist error is thrown. So clear the cache, restart bundler and try again. Or maybe the file is somehow created before you try to delete it. – Variag Jul 18 '23 at 21:40

0 Answers0