Home > Mobile >  Find Files in a Shared Drive with Apps Script
Find Files in a Shared Drive with Apps Script

Time:07-01

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

CodePudding user response:

Did you try like this?

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

CodePudding user response:

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
  • Related