Get File Explainer

Aim of the puzzle: Use Apps Script to get a file from Drive and print its name.

Walk through of the solution: Every file in Drive has a unique id. An id is a long string of characters and numbers, like this: accb4372522af72303e7bcd67a8e953189205bb6728a.

Apps Script has custom code functions that connect to Drive. One example is DriveApp.getFileById(), which takes an id and retrieves the matching file from Drive.

Another is .getName(), which returns the name of a file from Drive.

In the code that you start off with, the file with the id id1 is retrieved using DriveApp.getFileById(id1) and saved to the variable file. Then, its name is stored in the filename variable usingfile.getName() and printed to the console.

To complete the puzzle, change the id inside the parentheses of DriveApp.getFileById() from id1 to id2. This will retrieve a different file and print its name to the console.

Sample code solution:

let id1 = 'accb4372522af72303e7bcd67a8e953189205bb6728a';
let id2 = 'e514a7d3e2061ca9e33533074ded28a650a57cd24f04';

let file = DriveApp.getFileById(id2);
let fileName = file.getName();
console.log(fileName);

JavaScript concepts: Variables, Strings

Apps Script concepts: DriveApp, .getFileById(), .getName()

This code wont run at all ,it tells me that there is no console output.!!

Hey @March_Emmanuel!

Can you post a screenshot of your code?

Thanks!

Hi Guys! following my answer for this exercise: