11

I found myself accidentally sharing sensitive information in Google Drive. This has happened multiple times. So I want to check what I'm sharing and with whom. I'd like to see a list of my items (files and folders) in Drive, sorted by access level: first public, then people with the link, then shared with specific people, and finally private. Is that possible?

Or is there any other way of achieving this goal?

This question applies to Dropbox as well, for which I've posted a separate question as suggested.

  • Done. I updated the question with a link to the other question, and vice-versa. – Vaddadi Kartick Mar 7 '16 at 1:33
1

This script will get you pretty close to that goal. Here's an example of the output.

It's set up currently to run on a particular folder and subfolders but you could modify it to run on the entire drive (depending on the number of files it might time out).

  1. Open a new spreadsheet.
  2. Got to Tools>Script Editor
  3. Copy and paste the script below into that window replacing everything
  4. Put your folder ID in place of THE_FOLDER_ID
  5. Save it.
  6. Run the script by hitting the play (Run) button
  7. Go see what it wrote on the spreadsheet and sort however you'd like.

    function listFolders(folder) {
    var sheet = SpreadsheetApp.getActiveSheet();
    sheet.appendRow(["Name", "Sharing Access", "Sharing Permission", "Get Editors", "Get Viewers", "Date", "Size", "URL", "Download", "Description", "Type"]); //writes the headers
    var folder = DriveApp.getFolderById("THE_FOLDER_ID");//that long chunk of random numbers/letters in the URL when you navigate to the folder
    
    var files = folder.getFiles();//initial loop on loose files w/in the folder
    
     var cnt = 0;
     var file;
    
     while (files.hasNext()) {
         var file = files.next();
         var listEditors = file.getEditors(); //gets the editor email(s), doesn't show your own as it's assumed
         var editors = [];
         for (var cnt = 0; cnt < listEditors.length; cnt++) {
             editors.push(listEditors[cnt].getEmail());
             Logger.log(editors);
         };
         var listViewers = file.getViewers(); //gets the viewer email(s)
         var viewers = [];
         for (var cnt = 0; cnt < listViewers.length; cnt++) {
             viewers.push(listViewers[cnt].getEmail());
             Logger.log(viewers);
         }
         cnt++;  //data chunk pushes all the file info to the ss
    
         data = [
             file.getName(),
             file.getSharingAccess(),
             file.getSharingPermission(),
             editors.toString(),
             viewers.toString(),
             file.getDateCreated(),
             file.getSize(),
             file.getUrl(),
             "https://docs.google.com/uc?export=download&confirm=no_antivirus&id=" + file.getId(),
             file.getDescription(),
             file.getMimeType(),
         ];
    
         sheet.appendRow(data);
    
     };
    
    
     var subfolders = folder.getFolders(); //same thing as above but for all the subfolders in the folder
    
     while (subfolders.hasNext()) {
         //Logger.log(folder);
         var name = subfolders.next();
    
         var files = name.getFiles();
    
         var cnt = 0;
         var file;
    
         while (files.hasNext()) {
             var file = files.next();
             var listEditors = file.getEditors();
             var editors = [];
             for (var cnt = 0; cnt < listEditors.length; cnt++) {
                 editors.push(listEditors[cnt].getEmail());
                 Logger.log(editors);
             };
             var listViewers = file.getViewers();
             var viewers = [];
             for (var cnt = 0; cnt < listViewers.length; cnt++) {
                 viewers.push(listViewers[cnt].getEmail());
                 Logger.log(viewers);
             }
             cnt++;
    
             data = [
                 file.getName(),
                 file.getSharingAccess(),
                 file.getSharingPermission(),
                 editors.toString(),
                 viewers.toString(),
                 file.getDateCreated(),
                 file.getSize(),
                 file.getUrl(),
                 "https://docs.google.com/uc?export=download&confirm=no_antivirus&id=" + file.getId(),
                 file.getDescription(),
                 file.getMimeType(),
             ];
    
             sheet.appendRow(data);
    
             };
     }
    

    }

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.