Permanently delete file from google drive

Apps Script has the ability to access Google API’s, but you need to explicitly enable them before they can be used.

The Drive API, can be used to delete a file.

Drive API – Delete

The Drive API method is Remove method instead of Delete.

To enable the Drive API, open the Resources menu, then choose the Advanced Google Services, and a menu will pop up. You need to click the Drive API service. Make sure that the green “ON” text is showing.

enter image description here

Once you’ve done that, you can use the auto-complete in the code editor to see what is available for methods. When you type the word “Drive” in the code editor, then enter a period, a context menu will appear. Then you can choose Files, etc.

Drive.Files.remove(fileId);

NOTE:

Take note of the link: Google Developers Console

You must visit your Console, and enable the services there also. And it looks like the only way you can get to your Apps Script Project in the Console is through the link in that Advanced Google Services pop up window. Going to the Google console without the correct project number in the URL fails to show your Apps Script project.

You can get to the console with:

Google Console

But that is a dead end because it doesn’t show the Apps Script projects that you own.

Leave a Comment