Get ID of newly created Folder in Google Apps Scri

2019-08-03 03:35发布

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

1条回答
狗以群分
2楼-- · 2019-08-03 04:18

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();
查看更多
登录 后发表回答