Create doc move to specific folder

Below is a Google Apps Script that creates a new Google Document and moves it to a specific folder in Google Drive. This script assumes that you already have the folder’s ID where you want to place the new document.

  1. Open Google Apps Script by navigating to https://script.google.com.
  2. Start a new project by clicking on New Project.
  3. In the script editor, replace any code in the editor with the following script:
function createDocAndMoveToSpecificFolder() {
  var folderId = 'your-folder-id'; // Replace 'your-folder-id' with your actual folder ID
  var folder = DriveApp.getFolderById(folderId);
  
  // Create a new Google Doc in the root directory
  var doc = DocumentApp.create('New Document');
  var docId = doc.getId();
  
  // Log the URL of the new document for easy access
  Logger.log('New document created with URL: ' + doc.getUrl());
  
  // Move the new document to the specified folder
  var file = DriveApp.getFileById(docId);
  folder.addFile(file);
  DriveApp.getRootFolder().removeFile(file); // Remove the file from the root directory
  
  Logger.log('Document moved to the specific folder');
}
  1. Replace 'your-folder-id' with the ID of the folder where you want to create the new document. You can find this ID in the URL when you open the folder in Google Drive.
  2. Save the script by clicking on the disk icon or selecting File > Save, and give your project a name.
  3. To run the script, click on the play (triangle) button next to the function createDocAndMoveToSpecificFolder in the dropdown menu.
  4. The first time you run the script, you will be prompted to authorize the script. Follow the on-screen instructions to grant the necessary permissions.

After the script runs, it will create a new Google Document and move it to the specified folder. You can verify this by checking the specified folder in Google Drive. Also, the URL of the new document will be logged in the script’s log, accessible through View > Logs in the script editor.