You need to use this plugin: https://www.npmjs.com/package/cordova-plugin-file
I do not know which version of the cordova you are using, and if this plugin has been updated, but when I use it, it does not work with WindowsPhone. Good for Android and iOS.
To get the file system:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, downloadFile, fileSystemFail);
Download File Function:
downloadFile: function(fileSystem){
To create a directory:
var directoryEntry = fileSystem.root; var folderName = "Folder"; directoryEntry.getDirectory(folderName, { create: true, exclusive: false }, onDirectorySuccess, onDirectoryFail);
Where onDirectorySuccess and onDirectoryFail are functions such as:
onDirectorySuccess: function(parent){ console.log(parent); }, onDirectoryFail: function(error){ console.log("Unable to create new directory: " + error.code); }
To get the path to a file in a directory:
var filePath = directoryEntry.toURL() + "/" + folderName + "/" + fileName;
And get the file:
directoryEntry.getFile(folderName + "/" + fileName, { create: true, exclusive: false }, onFileSuccess, onFileFail);
To delete a file first, you need to get it:
directoryEntry.getFile(folderName + "/" + fileName, { create: true, exclusive: false }, onFileSuccessRemove, onFileFail);
Then in the function of success:
function onFileSuccessRemove(entry) { entry.remove(); }
My application was downloading a file, so this is the code to save the file in a directory:
var fileTransfer = new FileTransfer(); fileTransfer.download(URL, filePath, downloadComplete, downloadFail, true);
This is not your business, but I hope this helps.