$ cordovaFile.checkDir表示文件夹不存在,但$ cordovaFile.createDir表示文件夹已经存在 [英] $cordovaFile.checkDir says folder does not exist but $cordovaFile.createDir says folder already exists
问题描述
我正在尝试使用ngCordova文件插件,如下所示: http://ngcordova.com / docs / plugins / file / ,但会出现异常行为。
我想要创建一个文件夹,如果它不存在。我使用以下方式测试其存在:
$ cordovaFile.checkDir(cordova.file.dataDirectory,'inbound')
现在这会返回 NOT_FOUND_ERR
,所以我试着通过调用创建文件夹:
$ cordovaFile.createDir(cordova.file.dataDirectory,'inbound',false);
但这会返回 PATH_EXISTS_ERR
为什么checkDir告诉我它不存在, createDir告诉我它存在?
注意:这是使用Android设备。
这些是promise,你是否使用它们:
$ cordovaFile.checkDir(cordova.file。 dataDirectory,inbounds)
.then(function(success){
// success
alert(status+ success);
},function(error){
// error
});您是否已经配置了config.xml了吗?
< preference name =iosExtraFilesystemsvalue =library,library-nosync,documents,documents-nosync,cache,bundle,root/>
< preference name =AndroidExtraFilesystemsvalue =files,external,documents,sdcard,cache,cache-external,root/>
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.
解决方案 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" />
这篇关于$ cordovaFile.checkDir表示文件夹不存在,但$ cordovaFile.createDir表示文件夹已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!