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()

@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:

1 Like

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

here is lesson picture

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

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:

1 Like

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