Retrieving Specific Folders from Google Drive using Google Apps Script
These are sample scripts for retrieving specific folders from Google Drive using Google Drive service (DriveApp) with Google Apps Script.
Retrieving folders in own Google Drive
const folders = DriveApp.searchFolders(
`'${Session.getActiveUser().getEmail()}' in owners and trashed=false`
);
const res = [];
while (folders.hasNext()) {
const folder = folders.next();
res.push(folder.getName());
}
console.log(res);
Retrieving folders in shared Drives
const folders = DriveApp.searchFolders(
`not '${Session.getActiveUser().getEmail()}' in owners and trashed=false`
);
const res = [];
while (folders.hasNext()) {
const folder = folders.next();
const owner = folder.getOwner();
if (owner === null) {
res.push(folder.getName());
}
}
console.log(res);
Retrieving folders of sharedWithMe
const folders = DriveApp.searchFolders(`sharedWithMe`);
const res = [];
while (folders.hasNext()) {
const folder = folders.next();
res.push(folder.getName());
}
console.log(res);