Google AppScript is quite an useful service but there is a mechanism for files deletion that I don't understand. The same discussion applies to folder removal. I've replied some questions on SO where file removal was required, but there is still something that is not clear to me.
The DriveApp documentation explains the method DriveApp.removeFile
:
Removes the given file from the root of the user's Drive. This method does not delete the file, but if a file is removed from all of its parents, it cannot be seen in Drive except by searching for it or using the "All items" view.
I tried to inspect the behavior of such method with some testing script like this one:
function remove() {
var files = DriveApp.getFilesByName("file_to_remove");
while (files.hasNext())
DriveApp.removeFile(files.next());
}
but the result of this code is to remove only visually the file from my Drive web-interface (I'm not using clients), but the file (as from the documentation) still exist in "All Items".
Another way to remove the file is by setting it as trashed, thus it is actually removed the first time I clear the trash bin manually:
function trash() {
var files = DriveApp.getFilesByName("file_to_remove");
while (files.hasNext())
files.next().setTrashed(true);
}
but still, I do not like this approach (the file is still using part of my - extremely limited :P - quota).
A final method (that is what I'm using right now) employes the Advanced Google Services, for example:
function advanced_remove() {
var files = DriveApp.getFilesByName("file_to_remove");
while (files.hasNext())
Drive.Files.remove(files.next().id);
}
But what I don't like is the usage of the Services (that are limited in number of operations). Also it is possible through the Drive
object to empty the trash bin (Drive.emptyTrash()
, if I'm using the previous example)
IMHO the file removal is quite a basical operation that should be available through standard DriveApp API, and not by employing different approaches that do not completely remove the file or do require me to manually empty the trash.
My questions are:
- what is the real purpose of
removeFile
? And what means removed from all of its parents (I'm assuming parents are folders that contain the files)? - is there any actual way to remove completely the file without passing by the trash bin and without using advenced services?
- I'm not a native English speaker: Maybe Google Developers have implemented the methods considering a "semantic" difference between remove and delete?