Home > database >  Google Appscript - Scripting to copy existing folders with files by creating new folder
Google Appscript - Scripting to copy existing folders with files by creating new folder

Time:07-26

I am trying to use a script that creates a Parent folder and subfolders and also copies any templates within a drive

The sheet is here: enter image description here

  1. In line 136 you have to change the variable name templateDocId to templateFolderId this way:
var templateFolderId = data[i][1]
  1. After the line 152 the code should look like this:
// copy the template doc into the new directory (if specified)
// if(templateDocId != '') {
//   makeCopy(templateDocId, newFolderId, newFolderName   ' Template Document');
// }

if (templateFolderId != '') copy_files(newFolderId);

function copy_files(newFolderId) {
  var src_folder = DriveApp.getFolderById(templateFolderId);
  var dest_folder = DriveApp.getFolderById(newFolderId);
  var files = src_folder.getFiles();
  while (files.hasNext()) files.next().makeCopy(dest_folder);
}

After that the script will copy all the files from template folders into the new created folders (like 'Team A1', 'Team A2', etc).

The sheet with the changed script is here.

  • Related