How to overwrite a google drive html document from a script

565 Views Asked by At

I am trying to regularly regenerate an html file from a Google script that can be served from Google drive. In order to do this, I need to overwrite the html document in a way that doesn't change the document ID. The current code I have creates new versions of the same file, not overwrites the old file.

 var folder = DocsList.getFolder('site');
 var contents = "<B>Dynamic Content Goes Here</B>";
 folder.createFile('test.html', contents, 'text/html');  

Any assistance provided would be greatly appreciated

1

There are 1 best solutions below

0
On

Have you considered using the Drive API to update the file contents? This would overwrite the current contents with the new contents.

In order to use DriveAPI, you need to add it through the Resources, Advanced Google Services menu. Ensure the Drive API is set to ON.

Here is some additional information on the file update service:

https://developers.google.com/drive/v2/reference/files/update