I believe your goal as follows.
- You want to retrieve the file list of the files with the size of 217 bytes using Google Apps Script.
- You want to reduce the process cost of the script.
Issue and workaround:
Unfortunately, the search query of searchFiles
method has no value of size
. By this, your goal cannot be directly achieved. But I would like to propose the following workaround.
- When the file metadata has the value of file size, it is found that the files are not Google Docs files (Document, Spreadsheet, Slides and so on). Using this, the process cost can be reduced a little. And if the mimeTypes of files you want to retrieve are known, the file list can be also retrieved by searching the mimeType.
- When a lot of files are retrieved using Class DriveApp, the process cost of it is higher than that using Drive API.
So, I would like to propose to retrieve the file list using the search query of mimeType with the method of "Files: list" in Drive API.
Sample script:
function myFunction() {
const size = 217; // Please set the file size. In your question, it's 217 bytes.
const excludeMimeTypes = [MimeType.FOLDER, MimeType.GOOGLE_DOCS, MimeType.GOOGLE_DRAWINGS, MimeType.GOOGLE_FORMS, MimeType.GOOGLE_SHEETS, MimeType.GOOGLE_SITES, MimeType.GOOGLE_SLIDES, MimeType.GOOGLE_APPS_SCRIPT];
const q = excludeMimeTypes.map(e => `mimeType!='${e}'`).join(" AND ");
let res = [];
let pageToken = "";
do {
const r = Drive.Files.list({q: q, maxResults: 1000, pageToken: pageToken});
res = res.concat(r.items.filter(e => e.hasOwnProperty("fileSize") && e.fileSize == size));
pageToken = r.nextPageToken || "";
} while (pageToken);
console.log(res.length); // Here, you can see the number of files in the list.activate()
console.log(JSON.stringify(res)); // Here, you can see the file list.
}
References: