我有以下代碼將捕獲的圖像存儲在sdcard中的單獨目錄中。但是如何檢查特定的目錄是否存在?因爲如果存在,我想顯示該目錄中的圖像,如果不是,我想將捕獲的圖像保存到新目錄中。第二部分在我的代碼中。但幫助我的第一部分。當它進入ondeviceready事件我想檢查,目錄是否存在?如何檢查phonegap文件api中的現有目錄?
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);
};
}
您能否詳細說明'因爲如果存在我想要顯示來自該目錄的圖像,如果不是,我想將捕獲的圖像保存到新目錄中.' – gprathour 2013-05-01 08:48:31
當它進入ondeviceready事件時它應該詢問目錄名稱並且當用戶輸入目錄名稱,它應該檢查它是否已經存在。如果存在,它應顯示內容,我的意思是 – SSS 2013-05-01 08:52:58