I want to get a list of things with get list (which I have already coded in), but next, I want a delete button that deletes all the things on that list. How can I do that with Google Drive SDK and Javascript?
Example, if my criteria is:
q: "starred = "+test+" and viewedByMeTime < '"+n+""
How do I delete every single file that meets that criteria?
References: https://developers.google.com/drive/v2/reference/files/delete https://developers.google.com/drive/v2/web/search-parameters
I tried fitting search file and delete files together, but I am really bad at it and I am not sure which variable represents all the files found matching the criteria and how to get that variable to be fileID:
function DeleteFiles() {
var x = document.getElementById("ResultShown").value;
var date = new Date();
date.setDate(date.getDate() - 180);
var n = date.toISOString().split('.')[0] ;
var test = false;
gapi.client.drive.files.list({
pageSize: x,
q: "starred = "+test+" and viewedByMeTime < '"+n+"'",
fields: "nextPageToken, files(id)",
}
).then(function deleteFile(fileId)) {
var request = gapi.client.drive.files.delete({
appendPre('Files:');
var files = response.result.files;
if (files && files.length > 0) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
'fileId': fileId
});
request.execute(function(resp) { })
}
}
});
}