Stanley Levine
Stanley Levine

Reputation: 1

creating a google doc file in a specific folder

I create a google doc file and populate it from a presentation's notes. However, it puts the file in my root directory and not the directory of the presentation which is in a shared drive folder. I tired to move it but that did not work. Is there a way to create the document in the same folder as the slides? I have the folder ID. The code that I use to create it is:

`your text`    let docname = SlidesApp.getActivePresentation().getName();
`your text`    let doc = DocumentApp.create("Slide Notes - " + docname);
`your text`    let body = doc.getBody();

I then put the notes from each slide into body

I tried moving it but it did not move. addfile and removefile no longer works

Upvotes: 0

Views: 179

Answers (1)

Tanaike
Tanaike

Reputation: 201583

I believe your goal is as follows.

  • You want to create a new Google Document in the same folder of the parent folder of the active Presentation.
  • The parent folder of the active Presentation is the folder on the shared drive.

In this case, how about the following sample script?

Sample script 1:

const s = SlidesApp.getActivePresentation();
const fileId = s.getId();
const file = DriveApp.getFileById(fileId);
const parent = file.getParents().next();
let docname = s.getName();
let doc = DocumentApp.create("Slide Notes - " + docname);
DriveApp.getFileById(doc.getId()).moveTo(parent);
let body = doc.getBody();

When this script is run, a new Google Document is created in the same folder of the parent folder of the active Presentation.

Sample script 2:

As another approach, in this pattern, Drive API is used. So, please enable Drive API v3 at Advanced Google services.

const s = SlidesApp.getActivePresentation();
const fileId = s.getId();
const file = DriveApp.getFileById(fileId);
const parent = file.getParents().next();
const parentFolderId = parent.getId();

let docname = s.getName();
const { id } = Drive.Files.create({ name: "Slide Notes - " + docname, parents: [parentFolderId], mimeType: MimeType.GOOGLE_DOCS }, null, { supportsAllDrives: true });
let doc = DocumentApp.openById(id);
let body = doc.getBody();

References:

Upvotes: 0

Related Questions