在带有应用程序脚本的共享驱动器中查找文件

发布于 2025-02-12 15:32:49 字数 682 浏览 1 评论 0原文

此代码在文件夹中搜索一些文件。它在我的驱动器上很好,但是我需要在公司中的共享文件夹中,并且没有获得文件名和ID。我已经阅读了有关{supportSalldrives:true}的信息,但是我不知道如何在代码中实现它(我什至不知道它是否是解决方案)。 在我的项目中启用了驱动器API和Driveactivity API。

var expFolder = carpetabasecs.searchFolders(searchFor);
  while (expFolder.hasNext()) {
var expFolderDef = expFolder.next();
var expFolderId = expFolderDef.getId();

var mask = 'TXT';
var query = `title contains "${mask}" and trashed = false and "${expFolderId}" in parents`;
var findings = Drive.Files.list({ q: query }) || [];
var table = [['Archivos exportados', 'IDs'], ...findings.items.map(f => [f.title, f.id]).sort()];

sh.getRange(2,1,table.length,2).setValues(table);

谢谢

This code search for some files inside a folder. It work good on my drive, but I need it for a shared folder in my company and it does not get file names and ids. I've read about {supportsAllDrives: true} but I don't know how to implement it in the code (I don't even know if its the solution).
Drive API and DriveActivity API are enabled in my project.

var expFolder = carpetabasecs.searchFolders(searchFor);
  while (expFolder.hasNext()) {
var expFolderDef = expFolder.next();
var expFolderId = expFolderDef.getId();

var mask = 'TXT';
var query = `title contains "${mask}" and trashed = false and "${expFolderId}" in parents`;
var findings = Drive.Files.list({ q: query }) || [];
var table = [['Archivos exportados', 'IDs'], ...findings.items.map(f => [f.title, f.id]).sort()];

sh.getRange(2,1,table.length,2).setValues(table);

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

π浅易 2025-02-19 15:32:49

最后,我正在使用此方法来过滤文件。它在共享的驱动器上很好地工作。

  var suffix = 'TXT' // adapt as necessary
  var list = [];
  var files = expFolderDef.getFiles();
  while (files.hasNext()) {
    file = files.next();
    list.push([file.getName(),file.getId()])
  }
  var result = [['Archivos exportados','IDs'], ...list.filter(r => r[0].includes(suffix)).sort()]
  sh.getRange(2,1, result.length, result[0].length).setValues(result);

无论如何,我仍然有兴趣了解如何使用drive.files.list命令,underomainInAdminAccess和SupportAllDrives无法完成工作。我已经读到该命令是在高级驱动器服务中,API与驱动器API相同?因为我找不到云服务中的高级驱动器服务。

Finally I'm using this method to filter the files. It's working good on shared drives.

  var suffix = 'TXT' // adapt as necessary
  var list = [];
  var files = expFolderDef.getFiles();
  while (files.hasNext()) {
    file = files.next();
    list.push([file.getName(),file.getId()])
  }
  var result = [['Archivos exportados','IDs'], ...list.filter(r => r[0].includes(suffix)).sort()]
  sh.getRange(2,1, result.length, result[0].length).setValues(result);

Anyway I'm still interested in understand how to use the Drive.Files.list command, useDomaininAdminAccess and supportAllDrives don't make the work. I've read that the command is in Advanced Drive Service, that API is the same as Drive API? Because I can't find Advanced Drive Service in Cloud Services.

假装爱人 2025-02-19 15:32:49

你尝试过吗?

var findings = Drive.Files.list( { 
    q: query,
    useDomainAdminAccess: true
  }) || [];

Did you try like this?

var findings = Drive.Files.list( { 
    q: query,
    useDomainAdminAccess: true
  }) || [];
风和你 2025-02-19 15:32:49

更改以下内容:

var findings = Drive.Files.list({ q: query }) || [];

对此:

var findings = Drive.Files.list({ q: query, supportsAllDrives: true }) || [];

请记住,您正在使用驱动器v2(而不是v3)

文档

Change this:

var findings = Drive.Files.list({ q: query }) || [];

To this:

var findings = Drive.Files.list({ q: query, supportsAllDrives: true }) || [];

Remember that you are using the Drive v2 (not v3)

Documentation
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文