Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

403
Views
Find Files in a Shared Drive with Apps Script

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

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Did you try like this?

var findings = Drive.Files.list( { 
    q: query,
    useDomainAdminAccess: true
  }) || [];
about 4 years ago · Juan Pablo Isaza Report

0

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
  • Drive.File.list (v2)
about 4 years ago · Juan Pablo Isaza Report

0

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

  var sufix = '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(sufix)).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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!