Rename the File Explainer

Aim of the puzzle: Use Apps Script to rename a file from Drive.

Walk through of the solution: Apps Script has custom code functions that connect to Drive. One example is .setName(), which sets the name of a file from Drive. For example, myFile.setName('List of Lizards') sets the name of myFile to List of Lizards.

To complete the puzzle, change the string that’s inside the parentheses of file.setName() from ‘Inventory of Iguanas’ to a different string. Then, create a new variable called newName that stores the new name of the file using file.getName(). Finally, print newName to the console.

Sample code solution:

let id = '4FTT3tZLKLxIJhBNdyDCGc1rYJLUV8kQ4c4aodAZx8pE';
let file = DriveApp.getFileById(id);

let oldName = file.getName();

file.setName( 'List of Lizards');

let newName = file.getName();

JavaScript concepts: Variables, Strings

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

1 Like

were hether I don’t see the button

This part is typing, there’s no buttons.

Hi folks, following my answer for this exercise:

I don’t understand what did I do wrong?

Now I figured it out thank you