Is it possible to use Google Apps Script to search Google Drive for both documents and folders?
Google have killed their own docs/drive search gadget as it appears to rely on iGoogle and Google Enterprise support have admitted this.
Thank you
To run a function from the script editor, at the top, select the name of the function you want to execute and click Run.
Yes, a script from Google Apps Script on any Google Workspace Editor (Docs, Forms, Slides, Sheets) or any other place can access all your Google Drive files if they have requested the corresponding permission and you authorized the script to run.
I think you are looking for SearchFile and SearchFolder of the DriveApp. The full list of parameters is available in the Google Drive SDK documentation
I've run some tests and seems like it's not possible to do 1 search and get files and folders like it's possible calling the search function from the Google Drive API.
Here a code that list the files and folders with a title that have 2013 in it
function myFunction() {
var searchFor ='title contains "2013"';
var names =[];
var files = DriveApp.searchFiles(searchFor);
while (files.hasNext()) {
var file = files.next();
names.push(file.getName());
}
var folders = DriveApp.searchFolders(searchFor);
while (folders.hasNext()) {
var file = folders.next();
names.push(file.getName());
}
for (var i=0;i<names.length;i++){
Logger.log(names[i]);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With