Skip to content

Instantly share code, notes, and snippets.

@jleyva
Created July 28, 2014 11:14
Show Gist options
  • Save jleyva/df05458d20b72e3c30b8 to your computer and use it in GitHub Desktop.
Save jleyva/df05458d20b72e3c30b8 to your computer and use it in GitHub Desktop.
MM.fs.getDirectory = function(path, createIfNotFound, successCallback, errorCallBack, dirEntry) {
MM.fs.loadFS(function() {
path = path.replace('file:///', '');
var baseRoot = MM.fs.fileSystemRoot;
if (dirEntry) {
baseRoot = dirEntry;
}
MM.log('Getting directory '+path+' in '+ MM.fs.entryURL(baseRoot)+' '+createIfNotFound);
baseRoot.getDirectory(
path,
{create: false, exclusive: false},
function(newDirEntry) {
MM.log('Success!');
successCallback(newDirEntry, true);
},
function(error){
MM.log('Error!!');
if(createIfNotFound){
MM.log('File '+path+' doesnt exist. Lets create it.');
MM.fs.createDir(path, successCallback, dirEntry);
}
else{
MM.log('File '+path+' doesnt exist.');
errorCallBack(error);
}
}
);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment