【问题标题】:move generated google Form to specific google drive folder using google apps script使用谷歌应用脚​​本将生成的谷歌表单移动到特定的谷歌驱动器文件夹
【发布时间】:2021-03-11 02:59:05
【问题描述】:

我正在使用 Google Apps 脚本创建一些表单,该脚本会在我的 Google Drive 的根目录 (My Drive) 中自动生成。

我想将这些表单移动共享云端硬盘的特定文件夹中。

我在 Google 上搜索了有关将文件(或任何对象)移动到另一个文件夹的信息,其中大多数建议将文件复制到特定位置,然后从源位置删除

但在这种情况下,我的 formIds 正在改变,我不想改变。

有没有更好的方法将文件(在我的情况下是表单)移动到 Google Drive 中的另一个位置?

【问题讨论】:

    标签: google-apps-script google-drive-api google-forms


    【解决方案1】:

    作为开发人员,您应该始终偏爱规范资源,而不是在 google 搜索中弹出的 3rd 方教程。 Drive API 的官方文档有描述如何将文件从一个驱动器文件夹移动到下一个驱动器文件夹的指南。 I suggest you start there.

    【讨论】:

      【解决方案2】:

      以下代码适用于将任何文件(包括表单)移动到 Google Drive 中的目标文件夹:

      var fileId = '1234567890abcdefghijklmnopqrstuvwxyz'; //<--replace string with your file ID
      var destinationFolderId = 'zyxwvutsrqponmlkjihgfedcba0987654321';//<--replace string with your destination folder ID
      
      function moveFile(fileId,destinationFolderId) {
        var destinationFolder = DriveApp.getFolderById(destinationFolderId);
        DriveApp.getFileById(fileId).moveTo(destinationFolder);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-04
        • 2015-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多