asv
asv

Reputation: 3792

Subfolder in a specific folder with cordova

I have this function:

function createFolder(toDir, folderName, cb) {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
    function (fileSystem) {
        var entry = fileSystem.root;
        entry.getDirectory(folderName, {
            create: true,
            exclusive: false
        }, cb(), () => {});
    }, () => {});  
}

and I call

createFolder('file:///storage/emulated/0/', 'testFolder', ()=>{console.log('test');});

but it doesn't work.

Further, in the params I inserted toDir but I don't know how to use it to specify a directory where to create the subfolder folderName. I don't want use always fileSystem.root.

Upvotes: 0

Views: 202

Answers (1)

asv
asv

Reputation: 3792

I solved with this:

createFolder = function (toDir, folderName, cb) {
window.resolveLocalFileSystemURL(toDir, function (dirEntry) {
    function success(parent) {
        cb();
    }

    function fail(error) {
        alert("Unable to create new directory: " + error.code);
    }

    dirEntry.getDirectory(folderName, {
        create: true,
        exclusive: false
    }, success, fail);
});
}

Upvotes: 1

Related Questions