.getFilesByType versus .searchFiles

298 views
Skip to first unread message

jmm0979

unread,
Sep 30, 2021, 7:02:49 PM9/30/21
to google-apps-sc...@googlegroups.com
Hi,

I am do a full search of files in a folder except I only want the extract the following type of files:

var mimeType_query = (mimeType='application/vnd.google-apps.spreadsheet' or
mimeType='application/vnd.google-apps.document' or
mimeType='application/vnd.google-apps.presentation' or
mimeType='application/pdf')

Which is the correct method to use for this scenario and is my query correct?

driveLOC.getFilesByType(mimeType_query) or driveLOC.searchFiles(mimeType_query)
while (driveLOC.hasNext()) {
var drive_File = driveLOC.next();
...

TIA!



Tanaike

unread,
Sep 30, 2021, 9:36:00 PM9/30/21
to Google Apps Script Community
I think that "mimeType_query" is used for "searchFiles" method. Ref But "driveLOC.searchFiles(mimeType_query)" is required to be modified. Because "driveLOC" cannot be directly used as "while (driveLOC.hasNext())". And, I thought that "mimeType_query" is required to be modified. So in your script, how about the following modification?

var mimeType_query = "mimeType = 'application/vnd.google-apps.spreadsheet' or mimeType = 'application/vnd.google-apps.document' or mimeType = 'application/vnd.google-apps.presentation' or mimeType = 'application/pdf'";
var driveLOC = DriveApp.getFolderById("###folderId###").searchFiles(mimeType_query);
while (driveLOC.hasNext()) {
  var drive_File = driveLOC.next();
  console.log(drive_File.getName());
}

JMR...

unread,
Oct 4, 2021, 6:29:19 PM10/4/21
to Google Apps Script Community
Hi Tanaike,

Yes, I do have a separate call for "DriveApp.getFolderById("###folderId###")" = driveLOC.
It looks like my code is finally working properly, thank you for your advise. I just need to figure out now how to prevent it from timing out if the folder's file listing is too big.
Reply all
Reply to author
Forward
0 new messages