Home » Google AppScript30 January 2017

Google AppScript: Creating File, Folder & Google Doc

This article shows how to create a new folder and file with some text inside it with Google AppScript. We will also see how to create a new Google Doc and write some text inside it through AppScript.

Create File & Folder with AppScript

The following function will create a folder name My Folder in your Google Drive and then inside that folder it will create a file named My File.txt. It will also write some text (Lorem ipsum) in that file.

Create a new Google Doc File with AppScript

In the code below, we will be creating a new Google Doc named New Doc inside the folder My Folder. “My Folder” is the folder that we just created from above code.

To copy file into a folder, first of all we need the folder id.

– Go to your Google Drive
– Go inside the folder named “My Folder”
– See the URL in your browser’s address bar
– The URL will be something like this: https://drive.google.com/drive/folders/9tXNUNpM9tXNUNp0BydbYIIYLMxxxxxxxxxx
– The string after “folders/” will be your folder ID.
– So, in this case, the folder id is “9tXNUNpM9tXNUNp0BydbYIIYLMxxxxxxxxxx”

Note:

Files cannot be created directly inside already existing folders.
So, first you have to create a file in root directory.
Then, copy the file to speficied directory.
And then, delete the file present in root directory.

In below code, we will not write anything to the newly created doc file. We will just create the new doc file inside the speficied folder in Google Drive.

Create new Google Doc and write some content into it with AppScript

The following code will create a new Google Doc named TestDoc and write some Headings and Paragraphs on it. The doc file will be created in root folder of Google Drive.

Hope this helps. Thanks.

Google AppScript

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed