0
votes

I had a link of shared folder that is not in my google drive. It is a shared folder. Would i able to lists all the files in my google sheets using script editor? I've used this code but it is only applicable for the folder that is in my google drive.

function listFolderContents() {
  var foldername = 'your-folder';
  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] );     
  }  
};

Please Help.

1
I'm not sure what mean by list all of the files in your google sheets but yes you can access file in shared folders with Drives API. You will need to enable itCooper
@Cooper how do i enable it ?Sagar Chaulagain

1 Answers

1
votes

Try this for one folder with the folder's ID

function listing() {
  var folderID = '_______folder_ID_here_______'
  var folder = DriveApp.getFolderById(folderID);
  var contents = folder.getFiles();
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.appendRow( ['name', 'link'] );
  var file;
  var name;
  var link;
  while(contents.hasNext()) {
    file = contents.next();
    name = file.getName();
    link = file.getUrl();
    sheet.appendRow( [name, link] );     
  }  
};