Google Apps Script – MimeType.MICROSOFT_WORD Lists Only .docx

google-apps-scriptgoogle-drive

I am using a Google Apps Script to list Word files in a folder, however this will work only for .docx files, not .doc.
Any idea?

 var folderID = "ID#"
  var sourceFolder = DriveApp.getFolderById(folderID);
  var files = sourceFolder.getFilesByType(MimeType.MICROSOFT_WORD);
  // will list only .docx

Best Answer

How about this answer?

Pattern 1:

If you want to retrieve files with the extension of .doc, please modify as follows.

From:

MimeType.MICROSOFT_WORD

To:

MimeType.MICROSOFT_WORD_LEGACY

Pattern 2:

If you want to retrieve files with the extensions of .doc and .docx, please modify as follows.

From:

var files = sourceFolder.getFilesByType(MimeType.MICROSOFT_WORD);

To:

var files = sourceFolder.searchFiles("mimeType='" + MimeType.MICROSOFT_WORD_LEGACY + "' or mimeType='" + MimeType.MICROSOFT_WORD + "'");

References:

If I misunderstood your question and this was not the result you want, I apologize.