【问题标题】:JavaScript - Search through structure of folders - Google DriveJavaScript - 搜索文件夹结构 - Google Drive
【发布时间】:2014-11-07 10:46:14
【问题描述】:

使用 Google Apps 脚本我需要通过 Google Drive 中的文件夹结构进行搜索。问题是我不知道主文件夹中有多少级别的子文件夹(看一下图像)。我会一直在寻找“file-2”,但会有很多“file-2”,我需要找到所有这些。

我不知道子文件夹的名称和 ID。

我不知道需要搜索的文件“file-2”的 ID。

我只知道会有一个主文件夹,我需要搜索里面的所有文件“file-2”。

【问题讨论】:

    标签: javascript search google-apps-script google-drive-api directory-structure


    【解决方案1】:

    您不需要遍历所有文件夹和子文件夹,DriveApp 有一个searchFiles(params) method,它将返回所有具有该名称的文件,无论它们在哪里。

    示例:

     var files = DriveApp.searchFiles(
         'title contains "file-2"');
     while (files.hasNext()) {
       var file = files.next();
       Logger.log(file.getName());// file is a file object, it has methods to get parent folders if this info is useful... see same doc + links
     }
    

    【讨论】:

    • 谢谢伙计.. 成功了!
    猜你喜欢
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多