Reputation: 4263
I got some db files automatically backuped to my google drive. The backup routine adds the new db files (.lxdb) to a specific folder and removes the older ones.
On Google Drive the deleted files end up in the trash, quickly using up GBs of Drive space.
There are GA scripts to empty the trash periodically, however, I just want to remove that certain filetype, since it makes sense to keep all the other files in trash for security reasons.
function DeleteTrashedFiles(){
Drive.Files.emptyTrash();
};
However, whats a state of art way to request for an array of all the .lxbd files IN TRASH and then remove them? (better not by cycling through all the GD Files)
Upvotes: 1
Views: 1652
Reputation: 9872
You have two options:
.lxbd
files to Trash, simply delete them immediately. From Apps Script, with the enabled "Advanced Service" Drive
, this would be Drive.Files.remove(file.id);
Drive.Files.remove
for each of them.An example of option 2 for the Drive "Advanced Service" in Google Apps Script:
function deleteTrashedFiletype(someMimetype) {
var options = {
q: "trashed=true AND mimeType='" + someMimetype + "' AND '" + Session.getActiveUser().getEmail() + "' in owners",
pageToken: null
};
do {
var result = Drive.Files.list(options);
result.items.forEach(function (file) {
if(file.mimeType === someMimetype)
Drive.Files.remove(file.id);
else throw new Error("The query returned the wrong mimetype");
});
options.pageToken = result.nextPageToken;
} while(options.pageToken);
}
If you are dealing with Team Drive items you will have additional parameters that you need to include, and additional checks you must make if you require error-free operation.
Upvotes: 1