Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  10] [ 5]  / answers: 1 / hits: 33947  / 12 Years ago, mon, june 18, 2012, 12:00:00

I am using phonegap file api to create a directory and create a file in the directory created. The directory is getting created, but the file is not getting created in the directory.



The code I am using is:



document.addEventListener(deviceready, onDeviceReady, false);

function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
var dataDir = fileSystem.root.getDirectory(data, {create: true});
var file = dataDir.getFile(lockfile.txt, {create: true, exclusive: true});
}


The directory data is created but lockfile.txt is not getting created.


More From » cordova

 Answers
25

You need to call the code in an async manner:



document.addEventListener(deviceready, onDeviceReady, false);

function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
fileSystem.root.getDirectory(data, {create: true}, gotDir);
}

function gotDir(dirEntry) {
dirEntry.getFile(lockfile.txt, {create: true, exclusive: true}, gotFile);
}

function gotFile(fileEntry) {
// Do something with fileEntry here
}

[#84843] Friday, June 15, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sandy

Total Points: 59
Total Questions: 98
Total Answers: 98

Location: Falkland Islands
Member since Mon, Jul 13, 2020
4 Years ago
;