【发布时间】:2014-04-07 06:47:33
【问题描述】:
你可以用 GAS 在一个文件夹中的所有文档中搜索一个字符串并返回找到的文档列表吗?给我一个提示怎么做?
谢谢
拉斐尔
【问题讨论】:
标签: google-apps-script google-drive-api
你可以用 GAS 在一个文件夹中的所有文档中搜索一个字符串并返回找到的文档列表吗?给我一个提示怎么做?
谢谢
拉斐尔
【问题讨论】:
标签: google-apps-script google-drive-api
这在documentation 中都有描述,另请阅读有关搜索参数的详细信息described here。
他们也举了一个例子,下面是一个符合您要求的例子:
function testSearch(){
// Log the name of every file that contains a certain string
// you can get the folder of your choice here by its ID or by its name, in the second case the returned object is a folder iterator so you will have to iterate its content. There are examples all around on how to do that.
var files = DriveApp.getRootFolder().searchFiles(
'fullText contains "example"');
while (files.hasNext()) {
var file = files.next();
Logger.log(file.getName());
}
}
【讨论】: