The Apps Script Lab

The Apps
Script
Lab

Welcome! Just sharing some stuff I build with Apps Script, tips, tutorials, and whatever else I find useful ✨

5+ years in Apps Script and still exploring.

home-page-code

The Apps Script Lab

Welcome! Just sharing some stuff I build with Apps  Script, tips, tutorials, and whatever else I find useful ✨

5+ years in Apps Script and still exploring.

Drive Folder File Metadata
JS Code.gs

/**
 * Logs metadata for every file in a specific Drive folder using Drive API.
 *
 * @param {string} folderId - The ID of the Google Drive folder to scan.
 */
function logFilesMetadataInFolder(folderId) {
  let pageToken;
  do {
    const response = Drive.Files.list({
      q: `'${folderId}' in parents and trashed = false`,
      fields: "nextPageToken, files(id, name, mimeType, createdTime, modifiedTime, size,
      owners(displayName), lastModifyingUser(displayName), webViewLink)',
      pageSize: 1000,
      pageToken: pageToken,
    });

    const files = response.files || [];
    if (files.length === 0) {
      console.log('No files found.');
    } else {
      files.forEach(file => {
        console.log(`Name: ${file.name}`);
        console.log(`ID: ${file.id}`);
        console.log(`Type: ${file.mimeType}`);
        console.log(`Size: ${file.size || 'N/A'}`);
        console.log(`Created: ${file.createdTime}`);
        console.log(`Modified: ${file.modifiedTime}`);
        console.log(`Owner(s): ${file.owners.map(o => o.displayName).join(', ')}`);
        console.log(`Last modified by: ${file.lastModifyingUser?.displayName || 'N/A'}`);
        console.log(`Link: ${file.webViewLink}`);
        console.log('-----------------------------------');
      });
    }

    pageToken = response.nextPageToken;
  } while (pageToken);
}
    

The Apps Script Lab

Welcome! Just sharing some stuff I build with Apps Script, tips, tutorials, and whatever    else I find useful ✨

5+ years in Apps Script and still exploring.

home-page-code
Scroll to Top