I'm trying to rename a .pdf file in a google drive folder with Google App Script.
function findFilesInFolder() {
var childrenData = Drive.Children.list('XXXXXXX')
var children = childrenData.items;
//loops through the children and gets the name of each one
for (var i = 0; i < children.length; i++){
var id = children[i].id;
var file = Drive.Files.get(id);
file.setName('testname');
}
}
Looking at this doc https://developers.google.com/apps-script/reference/drive/file#setName(String) setName
is the right method to use.
file
is not valid. Log theid
After this line:var id = children[i].id;
Add:Logger.log('id: ' + id)
Run the code, then from the View menu, choose Logs. If there is noid
or if there is no file with thatid
then the variablefile
may not be a valid file. - Alan WellssetName
somewhere else? - Alan Wells