user5711693
user5711693

Reputation: 113

TypeError: Cannot find function makeCopy in object, google apps script

I am trying to copy a file which is in a different directory to the specified directory using google apps script. Please see the below example code:

function copyFile(){
   var file = "1vY42p5g7U1JqmHLCUqtAQSmptSPqxTDQrkVvfxndZdI";
   var folder = "0B2F4vEzC6qMLOV9LR05SbmwtTmc"; 
   file.makeCopy(folder); 
}

I keep getting this error TypeError: Cannot find function makeCopy in object:1vY42p5g7U1JqmHLCUqtAQSmptSPqxTDQrkVvfxndZdI. I am not sure why this is happening.

Can someone please suggest if I am using the function makeCopy correctly?

Upvotes: 0

Views: 2429

Answers (1)

user3717023
user3717023

Reputation:

You are confusing a File object with a String that holds the Id of a file. It's about the same difference as between John Smith, a person, and "John Smith", a string of characters. To get a File with given Id, use the method getFileById of DriveApp:

var file = DriveApp.getFileById("1vY42p5g7U1JqmHLCUqtAQSmptSPqxTDQrkVvfxndZdI");

Similarly,

var folder = DriveApp.getFolderById("0B2F4vEzC6qMLOV9LR05SbmwtTmc");

Upvotes: 3

Related Questions