In my Windows 8 application, I am wanting to removed all cached documents stored in the LocalState folder where I stored them for use while in the application.
var deleteFolderPromise = Windows.Storage.ApplicationData.current.localFolder.deleteAsync("\\fileName").done(
function (result) {
console.log("File removed: " + Windows.Storage.ApplicationData.current.localFolder.path + "\\fileName");
},
function (error) {
console.log("File not removed" + error);
});
Every time this code runs it deletes the entire LocalState folder and not the folder or file I specify in the deleteAsync(). How do I modify the code to remove just the specified folder or file. Do I need to use a getFileAsync()/getFolderAsync() and pass that result as a parameter to the deleteAsync() method?
The deleteAsync folder is an instance method that operates on the StorageFolder through which you call it. In your case, you're calling it on the localFolder object and thus see that folder being deleted.
Instead, you need to obtain the local folder first, then obtain from it the specific StorageFolder you want, then call it's deleteAsync as you suspected, that is:
Windows.Storage.ApplicationData.current.localFolder.getFolderAsync("folder_name").then(function (folder) {
return folder.deleteAsync();
}).done(function () {
//Success
}, function (err) {
//Error
});