我有以下代码将捕获的图像存储在 sdcard 的单独目录中。但是如何检查特定目录是否存在?因为如果存在,我想显示该目录中的图像,如果不存在,我想将捕获的图像保存到新目录中。第二部分在我的代码中。但是请帮助我完成第一部分。当它进入我想检查的 ondeviceready 事件时,目录是否存在???
function getImageURI(imageURI) {
capturedImgId++;
var imgId = "img"+capturedImgId;
document.getElementById(imgId).src = imageURI;
document.getElementById(imgId).style.display = 'block';
createButton(capturedImgId);
var gotFileEntry = function(fileEntry) {
alert("got image file entry: " + fileEntry.fullPath);
var gotFileSystem = function(fileSystem) {
fileSystem.root.getDirectory("BangaloreFolder", {
create : true
}, function(dataDir) {
// copy the file
dataDir.getDirectory(today+"-T"+teamNo, {
create : true
},function(dataDir1) {
fileEntry.moveTo(dataDir1, capturedImgId+".jpg", null, fsFail);//try out with capturedImgId.jpg
});
}, dirFail);
};
// get file system to copy or move image file to
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem,
fsFail);
};
// resolve file system for image
window.resolveLocalFileSystemURI(imageURI, gotFileEntry, fsFail);
// file system fail
var fsFail = function(error) {
alert("failed with error code: " + error.code);
};
var dirFail = function(error) {
alert("Directory error code: " + error.code);
};
}