I am trying to write a script that will allow me to search within all of google drive, including shared teams and subfolders (Many Subfolders)
With what I wrote I can't find all the files, in fact there is a discrepancy between the ones I see from the web page and the ones the script returns to me
This is just a part of the script, when the file is found, it is moved to a folder. I have several files to move, via browser it is not manageable.
function SearchFiles() {
//Please enter your search term in the place of Letter
var searchFor ='title contains "find ME"';
var names =[];
//var fileIds=[];
var files = DriveApp.searchFiles(searchFor);
while (files.hasNext()) {
var file = files.next();
//var fileId = file.getId();// To get FileId of the file
//fileIds.push(fileId);
var name = file.getName();
names.push(name);
}
for (var i=0;i<names.length;i++){
Logger.log(names[i]);
//Logger.log("https://drive.google.com/uc?export=download&id=" + fileIds[i]);
}
}
DriveApp
Gets a collection of all files in the user's Drive
Advanced Drive Service
based on the Drive API v2 allows you to set the parameters supportsAllDrives
and includeItemsFromAllDrives
to true
and thus obtain results from all DrivesAdvanced Drive Service
, first you need to enable it following the instructionsq
to title contains 'find ME'
In Apps Script it could look as following:
function SearchFiles() {
var searchFor ='title contains "findMe"';
var files = Drive.Files.list({supportsAllDrives: true, includeItemsFromAllDrives: true, q: searchFor}).items;
for (var i=0; i<files.length; i++){
Logger.log(files[i].title);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.