7

I'm using the web version of Google Drive, which is not synced with any computer. I want to view the number of files inside this folder. There are hundreds of files in this folder, so scrolling through them is not an option. How would I be able to do this?

3

Copied from here but very similar to other versions:

// replace your-folder below with the folder for which you want a listing
function listFolderContents() {
  var foldername = "WA";
  var folderlisting = 'listing of folder ' + foldername;
  var folders = DriveApp.getFoldersByName(foldername)
  var folder = folders.next();
  var contents = folder.getFiles();
  var ss = SpreadsheetApp.create(folderlisting);
  var sheet = ss.getActiveSheet();
  sheet.appendRow( ['name', 'link'] );
  var file;
  var name;
  var link;
  var row;
  while(contents.hasNext()) {
    file = contents.next();
    name = file.getName();
    link = file.getUrl();
    sheet.appendRow( [name, link] );     
  }  
};

I chose folder WA for testing and the results (names and URLs) were returned to a file called list of folder WA (so your-folder in the comment is WA in the code above).

Open a sheet (a new one perhaps), Tools > Script editor and copy all of the above code into the code window. No need to give it or the project a name but you will need to save the code and to authorise it. Whereupon Google will probably object, but not prevent the code working. Then Run it and go find file list of folder xxxx. The count of files may be read from the row number of the last entry (less one for the headings).

Substitute the following for Lines 10 - 19 to return files sizes also:

sheet.appendRow( ['name', 'link','size'] );
  var file;
  var name;
  var link;
  var size;
  var row;
  while(contents.hasNext()) {
    file = contents.next();
    name = file.getName();
    link = file.getUrl();
    size = file.getSize();
    sheet.appendRow( [name, link, size] ); 
  • I totally missed that, the file is there. Looks like it works, thanks. Just one thing to note for anyone reading this: it doesn't seem to work with directories, just files (which isn't a problem for me) – Skeleton Bow Dec 5 '17 at 14:15
  • 1
    By the way, how does this work for folders with non-unique names? Would you have to change the name to be unique and then revert it? I tried putting two folders with the same name inside the same parent folder, and it seems to have output the information for the folder nearer to the top. – Skeleton Bow Dec 5 '17 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.