/**
* list as many shared drives as you want (maxResults)
* useDomainAccess = false so you get only shared drives you can access
*/
function SharedDriveList() {
// Get (first n) Shared Drives for domain (1 in this example)
const drives = Drive.Drives.list({useDomainAdminAccess: false, maxResults: 1}).items;
console.log("sharedDriveItems: " + drives );
drives.forEach(drive => generateDriveFiles(drive));
}
/**
* list all of the files within the shared drive, one shared drive at a time
*
*/
function generateDriveFiles(drive) {
// get all files on this drive
let filesList = [];
console.log('Getting all files');
// exclude folders
// const filesQuery = "trashed = false AND '"+drive.id+"' = teamDriveId AND mimeType != 'application/vnd.google-apps.folder'"; const filesQuery = "trashed = false AND mimeType != 'application/vnd.google-apps.folder'";
filesList = driveCall_(filesQuery,drive);
// constructing the 2d array for google sheets
const heads = [['Path', 'Name', 'ID', 'Link', 'Created Date', 'Modified Data', 'Mime Type', 'Size', 'Shared Drive ID']];
const res = filesList.map(f => {
f.path = 'thisfolderpath';
return [f.path, f.name, f.id, f.webViewLink, new Date(f.createdTime), new Date(f.modifiedTime), f.mimeType, f.quotaBytesUsed,f.teamDriveId]
});
// writing the results to the report
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1]
sheet.getRange(1, 1, res.length + 1, res[0].length).setValues([...heads, ...res]);
sheet.getRange(2, 1, res.length, res[0].length).sort([1, 2])
}
/**
* Make Drive API v3 files.lists calls
* @param {String} optional query term
* @return {Object} files resource object array
*/
function driveCall_(filesQuery,drive) {