在驱动器加载项(右侧边栏):获取当前文件夹和选定的文件



我目前正在开发DRIVE加载项。

我想添加一个函数来选择文件->更改名称->移动到选定的文件夹。

你知道在我的加载项中获取当前文件夹和选定文件的方法吗???

访问当前所选项目

您可以使用清单指定以下内容:

"drive": {
"homepageTrigger": {
"runFunction": "onHomePage",
"enabled": true
},
"onItemsSelectedTrigger": {
"runFunction": "funcname"
}
}

传递给函数的事件对象

function funcname(e) {
//e contains an event object

Sample Event Object:
{
"commonEventObject": { ... },
"drive": {
"activeCursorItem":{
"addonHasFileScopePermission": true,
"id":"0B_xxxxx",
"iconUrl": "https://drive-thirdparty.googleusercontent.com...",
"mimeType":"application/pdf",
"title":"How to get started with Drive"
},
"selectedItems": [
{
"addonHasFileScopePermission": true,
"id":"0B_xxxxxx",
"iconUrl":"https://drive-thirdparty.googleusercontent.com...",
"mimeType":"application/pdf",
"title":"How to get started with Drive"
},
...
]
},
...
}

e.selectedItems.id包含所选项目的id

如果选择了一个文件,您可以获得id和文件,父级将提供当前文件夹。mimeType可用于区分文件和文件夹

插件事件对象

一个简单的驱动器插件,用于提供所选项目的id和mimeTypes

function onHomePage(e) {
//Logger.log(JSON.stringify(e));
var cards = [];
cards.push(displayFileId(e));
return cards;
}
function displayFileId(e) {
var card = CardService.newCardBuilder();
card.setHeader(CardService.newCardHeader().setTitle('File Information'));
var section = CardService.newCardSection();
var idtxt = CardService.newTextParagraph().setText('Click on a file to get file id');
section.addWidget(idtxt);
card.addSection(section);
return card.build();
}
function onMyDriveItemSelected(e) {
var s = '';
if (e.drive.selectedItems.length > 0) {
e.drive.selectedItems.forEach(function(itm,i)  {
if (i > 0) { s += '<br><br>'; }
s += Utilities.formatString(' %s<br>%s<br> ', itm.id,itm.mimeType);
});
}
var card = CardService.newCardBuilder();
var section = CardService.newCardSection();
var infotxt = CardService.newTextParagraph().setText(s);
section.addWidget(infotxt);
card.addSection(section);
return card.build();
}

最新更新