Per Apps Script documentation, the .removeFile(fileId)
method does not delete the file, nor does it trash the file. This method simply removes the file from the current folder.
To delete a file from Google Drive via Apps Script will require using the Drive REST API
possibly as an advanced service. This will skip the "Trash" - it is unrecoverable.
function deleteIt(fileId) {
var file = Drive.Files.get(fileId);
if(file.mimeType === MimeType.FOLDER) {
// possibly ask for confirmation before deleting this folder
}
Drive.Files.remove(file.id); // "remove" in Apps Script client library, "delete" elsewhere
}
"Trash"ing a file/folder can be done from Google Apps Script without needing to set up and configure the advanced service:
function trashIt(fileId) {
var file;
try {
file = DriveApp.getFileById(fileId);
}
catch (fileE) {
try {
file = DriveApp.getFolderById(fileId);
}
catch (folderE) {
throw folderE;
}
}
file.setTrashed(true);
}
(Trashing can also be done with the Advanced Service if you need to work with Team Drive items.)
See related questions:
Permanently delete file from google drive
Delete or Trash specific file in Drive
Google apps script : How to Delete a File in Google Drive?