我正在尝试写一个脚本,允许我搜索所有谷歌驱动器,包括共享团队和子文件夹(许多子文件夹)。
用我写的东西,我找不到所有的文件,事实上,我从网页上看到的文件和脚本返回给我的文件是不一致的
这只是脚本的一部分,当找到文件时,它会被移动到一个文件夹中。我有几个文件要移动,通过浏览器是无法管理的。
function SearchFiles() {
//Please enter your search term in the place of Letter
var searchFor ='title contains "find ME"';
var names =[];
//var fileIds=[];
var files = DriveApp.searchFiles(searchFor);
while (files.hasNext()) {
var file = files.next();
//var fileId = file.getId();// To get FileId of the file
//fileIds.push(fileId);
var name = file.getName();
names.push(name);
}
for (var i=0;i<names.length;i++){
Logger.log(names[i]);
//Logger.log("https://drive.google.com/uc?export=download&id=" + fileIds[i]);
}
}发布于 2022-07-07 13:38:13
要查找所有文件,包括共享驱动器上的文件,需要使用高级驱动服务而不是DriveApp
获取用户的驱动器中所有文件的集合
Advanced Drive Service的驱动API v2允许您将参数supportsAllDrives和includeItemsFromAllDrives设置为true,从而从所有驱动器获得结果。Advanced Drive Service,首先需要在使用说明之后启用它q设置为title contains 'find ME'。在Apps脚本中,它可以如下所示:
function SearchFiles() {
var searchFor ='title contains "findMe"';
var files = Drive.Files.list({supportsAllDrives: true, includeItemsFromAllDrives: true, q: searchFor}).items;
for (var i=0; i<files.length; i++){
Logger.log(files[i].title);
}
}https://stackoverflow.com/questions/72896876
复制相似问题