1

I am trying to create a script for my classes that will copy 2 files (templates) as soon as I create a folder. Something like this:

  1. Create new folder /new_student/ in the folder Google_drive/customer_class_b/
  2. Copy the files student_guidelines.gdoc and student_acknowledgement.gdoc from Google_drive/resources to Google_drive/customer_class_b/
  3. Rename the files student_guidelines.gdoc and student_acknowledgement.gdoc to student_guidelines_class_b.gdoc and student_acknowledgement_class_b.gdoc

Result should be having 2 files: Google_drive/customer_class_b/student_guidelines_class_b.gdoc and Google_drive/customer_class_b/student_acknowledgement_class_b.gdoc

I tried to play with the scripts but I am struggling. Any idea of how we could do so?

Kunlun
  • 53
  • 3
  • 6
  • 2
    Please be more specific. Can you write some code that you have tried. It will be helpful to understand your problem – Vasim Sep 19 '16 at 11:06
  • I am really not a coder so I am not sure it would be of any help if I copy what I tried, sorry :| Even declaring the functions is a struggle... – Kunlun Sep 19 '16 at 12:40

1 Answers1

3

As @Vasim said, we can help you better if you provided some code or error code that you encountered.

From this documentation, you can copy a file using the makeCopy() method; makeCopy(destination) to copy the file in the destination directory; makeCopy(name) to create a copy of the file and names it with the name provided; and makeCopy(name, destination) to copy the file in the destination directory and names it with the name provided.

Here is an example from Google apps script examples - Copy file and move to another folder:

function copyfile() {
var file = DriveApp.getFileById("1pkwQ9te-EtpqC_NC3BoHzOTUoC7axZDcAfxrqMgslwg");
var source_folder = DriveApp.getFolderById("0B8_ub-Gf21e-fkxjSUwtczJGb3picl9LUVVPbnV6Vy1aRFRWc21IVjRkRjBPTV9xMWJLRFU")
var dest_folder = DriveApp.getFolderById("0B8_ub-Gf21e-flJ4VmxvaWxmM2NpZHFyWWxRejE5Y09CRWdIZDhDQzBmU2JnZnhyMTU2ZHM")
// Make a backup copy.
var file2 = file.makeCopy('BACKUP ' + Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd') + '.' + file.getName());
dest_folder.addFile(file2);
source_folder.removeFile(file2);
}

You can check on these related threads:

Hope this helps!

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59