Skip to content

Instantly share code, notes, and snippets.

@bytrangle
Last active December 16, 2020 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bytrangle/ea733479b33609a490bead421c2efb40 to your computer and use it in GitHub Desktop.
Save bytrangle/ea733479b33609a490bead421c2efb40 to your computer and use it in GitHub Desktop.
Search Files in Google Drive Whose Names Matches a Given Value
/* Example: Search for all files in Google Drive whose file names contains the word 'tracker'. The result would be:
- Fitness tracker
- Personal finance tracker
- Job application tracker
*/
function searchFiles(name) {
var results = [];
var query = `title contains "${name}"`;
var files = DriveApp.searchFiles(query);
while (files.hasNext()) {
var file = files.next();
results.push(file);
Logger.log([file.getDateCreated(), file.getName(), file.getUrl(), file.getMimeType()].join());
}
return results
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment