列出电子表格中Google驱动器文件夹中的文件 [英] List files inside a google drive folder in spreadsheets

查看:42
本文介绍了列出电子表格中Google驱动器文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹:

我该怎么办?

解决方案

解决方案:

以下代码将完成这项工作:

  function findFilesInfo(){const folderId ='1_70Q4BPQrOHCQU4eUleEPuxbr0hpfhBB'const文件夹= DriveApp.getFolderById(folderId)常量文件= folder.getFiles()const source = SpreadsheetApp.getActiveSpreadsheet();const sheet = source.getSheetByName('Página1');const data = [];while(files.hasNext()){const childFile = files.next();var info = [childFile.getName(),childFile.getUrl(),childFile.getLastUpdated(),Drive.Files.get(childFile.getId()).lastModifyingUser.displayName];data.push(info);}sheet.getRange(2,1,data.length,data [0] .length).setValues(data);} 

要求:

  1. 创建一个名称为Página1的工作表(您当然可以对其进行调整根据您的需求)具有以下结构:

  1. 有资源>进阶Google服务:启用 Drive API :

  1. 在此处指定文件夹的文件夹ID":

      const folderId ='1_70Q4BPQrOHCQU4eUleEPuxbr0hpfhBB'; 

限制:

不能在您的Google工作表文件中使用 findFilesInfo()作为自定义函数.您可以通过点击播放按钮直接从Google脚本编辑器中运行它:

或者您可以创建一个自定义按钮(宏),您可以在其中从Google工作表文件中单击该按钮并执行该功能.

I have a folder: https://drive.google.com/drive/folders/1_70Q4BPQrOHCQU4eUleEPuxbr0hpfhBB

This folder has some files inside. I want to create a google-appscript to list the files in a Spreadsheet, in a way it look as close as possible to this: https://docs.google.com/spreadsheets/d/11KQYtJvEi1nbw0Awp7xgitOPgc9RhkMLICBGvvJrYlU/edit#gid=0

How could I do that?

解决方案

Solution:

The following code will do the job:

function findFilesInfo() {

  const folderId = '1_70Q4BPQrOHCQU4eUleEPuxbr0hpfhBB'
  const folder = DriveApp.getFolderById(folderId)
  const files = folder.getFiles()
  const source = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = source.getSheetByName('Página1');
  const data = [];
  
  while (files.hasNext()) {
      const childFile = files.next();
      var info = [ 
        childFile.getName(), 
        childFile.getUrl(),
        childFile.getLastUpdated(),
        Drive.Files.get(childFile.getId()).lastModifyingUser.displayName     
      ];
    
    data.push(info);
  }
  sheet.getRange(2,1,data.length,data[0].length).setValues(data);
}

Requirements:

  1. Create a sheet with the name Página1 (you can adjust it of course according to your needs) that has the following structure:

  1. In Resouces > Advanced Google services: enable Drive API:

  1. Specify the 'folderID' of your folder here:

    const folderId = '1_70Q4BPQrOHCQU4eUleEPuxbr0hpfhBB';
    

Restrictions:

You can't use findFilesInfo() as a custom function within your google-sheet file. You can either run it directly from google script editor by clicking on the play button:

or you can create a custom button (macros) where you can click on it from your google-sheet file and execute the function.

这篇关于列出电子表格中Google驱动器文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆