How to use Google Apps Script to display the number of files in a Google drive

Asked 1 years ago, Updated 1 years ago, 43 views

Enter image description hereEnter image description here was insufficient.
As shown in the image above, I would like to use GAS to reflect the number of files in Google Drive corresponding to each item in the spreadsheet in the Number of Cases column. How can I do this?As shown in the image below, the folders in the Google drive are divided into items, and I would like to reflect the number of files in this folder for each item.
Please help me.

google-apps-script

2022-09-30 21:25

1 Answers

Loop all files in your Google drive with DriveApp.getFiles() and count each time to get the number of files.
"Also, it seems that ""shared items"" and ""recently used items"" are counted."
Also, if you have a large number of files, it may not be finished within the Google AppsScript time limit, so you may need to think about it separately.

function myFunction(){
  var count = 0;
  var files = DriveApp.getFiles();
  while(files.hasNext()){
    count++;
    var file=files.next();
  }
  SpreadsheetApp.getActiveSheet().getRange("A1").setValue(count);
}


2022-09-30 21:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.