$cordovaFile.checkDir says folder does not exist but $cordovaFile.createDir says folder already exists

冷暖自知 提交于 2019-12-22 10:37:46

问题


I am trying to work with the ngCordova File plugin as documented here: http://ngcordova.com/docs/plugins/file/, but am getting strange behaviour.

I am trying to create a folder if it does not already exist. I am testing for its existence using:

$cordovaFile.checkDir(cordova.file.dataDirectory, 'inbound')

Now this returns NOT_FOUND_ERR so i try to create the folder subsequently by calling:

$cordovaFile.createDir(cordova.file.dataDirectory, 'inbound', false);

But this then returns PATH_EXISTS_ERR

Why would checkDir tell me it does not exist, but then createDir tell me it DOES exist?

NOTE: This is using an Android device.


回答1:


Those are promises, are you using them like that :

$cordovaFile.checkDir(cordova.file.dataDirectory, "inbounds")
      .then(function (success) {
        // success
        alert("status " + success);


      }, function (error) {
        // error
      });

Have you configured your config.xml too ?

<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root" />



回答2:


OK, I am adding this as an answer although aorfevre started the whole ball rolling. The issue I had primarily was that I had not added the necessary lines to my config.xml file which provided access to the device's filesystem.

Although after doing this I still had issues the key thing I was doing wrong was building and redeploying the app over the top of the existing installation. As soon as I manually uninstalled the app and deployed it fresh, it started working fine.



来源:https://stackoverflow.com/questions/30188947/cordovafile-checkdir-says-folder-does-not-exist-but-cordovafile-createdir-says

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!