Reputation: 69
As part of a Google Apps Script project, I'm trying to move the active spreadsheet and several uploaded files to a new folder that is created within a shared directory.
I have been able to create the new folder with:
DriveApp.getFolderById(parentFolder).createFolder(rename);
But to be able to move the files where I need to know the ID of the folder that's just been created.
The rest of the code works ok - if I just put in a string as another folders ID everything gets moved. I'm just stuck on actually finding that new folder ID.
Any ideas?
ta
Upvotes: 3
Views: 19198
Reputation: 201378
You can retrieve folder ID using "getId()". For example, your code can be written as follows.
var id = DriveApp.getFolderById(parentFolder).createFolder(rename).getId();
If the folder name is only one on Drive, you can retrieve folder ID from folder name like below.
var id = DriveApp.getFoldersByName(rename).next().getId();
Upvotes: 8