Copy the File Explainer

Aim of the puzzle: Use Apps Script to create a copy of a file in Drive and print its id.

Walk through of the solution: Apps Script has custom code functions that connect to Drive. One example is .makeCopy(), which creates a copy of a file from Drive. It returns a new file that has the same contents as the file it copied but a different id. Another example is .getId(), which gets the id of a file from Drive.

To complete the puzzle, create a variable called secondCopy that stores a new copy of file using file.makeCopy(). Then, create another variable called secondCopyId that stores the id of secondCopy using secondCopy.getId(). Finally, print secondCopyId to the console.

Sample code solution:

let id = '1gJAiEKJd8NMdjI_EcI12y3iIYk3E8wokAJEOijsZcf0';
let file = DriveApp.getFileById(id);

let firstCopy = file.makeCopy();
let firstCopyId = firstCopy.getId();
console.log(firstCopyId);

let secondCopy = file.makeCopy();
let secondCopyId = secondCopy.getId();
console.log(secondCopyId);

JavaScript concepts: Variables, Strings

Apps Script concepts: DriveApp, .getFileById(), .makeCopy(), .getId()

2 Likes

@grasshopperexplainerWill you help me please??? here is my code

Hi there RyanZhou. Happy to help! :smile:
At line 9, you wrote secondCopyid but inside your print() statement, you’re printing secondCopyId, even though it is not defined yet. Try renaming it to secondCopyId variable. Hope this makes you pass.

Hope this help. If this solution did not work then ask me any question. :smiley:
Pummarin :smile:

EDIT: Why did you download my profile picture and then apply it to your profile picture?? :face_with_raised_eyebrow:

2 Likes

click or tap to reveal Your profile picture is so cool and I like it :laughing: :laughing: :joy: :rofl: before I changed my profile picture of moose and Pummarin_The_Gamer! here is the picture!
Screen Shot 2020-09-13 at 6.07.35 pm|690x386

1 Like

here is lesson picture

that is strange can you give your one for me??? :question: :question: :question: :question:

1 Like
1 Like

Hello again RyanZhou. Maybe after you think my answer is strange, try reading @grasshopperexplainer’s post, the solution code is at @grasshopperexplainer’s top topic. :blush:

Thank you!
Pummarin :smile:

2 Likes

click or tap to revele Hey there do you like my profile picture you can wear it!! and it looks like we are friends!

1 Like

um… i cant see anything i’m going to get mad knowwwwwwwww show me what it says i hope you read my part that i just did okay so you can know all about me and your not going to like it i’m telling you right know your not going to like it

ohhhhh sorry i just needed to tap or click

hi :wave:t5: :wave:t5:

i am new :wave: :grin:

In the 8th line of your code the variable’s name is secondCopyid but the name had to give is
secondCopyId make sure the i is in capital.

I’m a bit confused or I might just not understand. I thought that variables were just ways to store information, but you still needed to call that variable in some other line of code for that variable’s code to execute.

In this exercise, we are creating variables but I don’t see where we are telling it to run. We are using console.log to print out the file id of both files, but that appears to be it. Sorry if it’s a dumb question.