-3

In the situation if someone leaves a company, to transfer all the files (Spreadsheets, Documents, Sites, Slides etc) they own to someone else, is there any method or a function to list the files using apps script ?

For instance, if I am trying to list all Spreadsheets owned by person with email "xyz@google.com", may be like SpreadsheetApp.getSheetsOwnedBy("xyz@google.com"). I tried finding something like this but could not find any. Could anyone please share your knowledge on this if you have idea.

Thanks in advance!!!

Teja
  • 1
  • 1
  • 1
    Deleting and posting back doesn't change the fact that the question is duplicate. https://stackoverflow.com/questions/65306744/ – TheMaster Dec 16 '20 at 06:46

2 Answers2

0

Yes, you can transfer files from a user with the Data Transfer API

You need to be an admin to do so.

There is a nice post showing you in detail on how to perform the transfer in Apps Script.

ziganotschka
  • 25,866
  • 2
  • 16
  • 33
0

I found that this below code could satisfy my requirement, I will leave this piece of code here just in case someone has similar requirement.

`

function transferOwnership() {
 

 var count = 0;  //to keep track of total no. of files
 var files = DriveApp.searchFiles('"me" in owners'); //can give emailAddres in place of "me"
// var files = DriveApp.searchFiles('title contains "untitled"'); //gives list of files containing the files that incluede "untitled" in file title
 
while (files.hasNext()) {
 var file = files.next();
 count++;
 Logger.log(file.getName());
 Logger.log(file.getMimeType());  //to know under which mime type category the file falls under
 //file.setOwner("xyz@google.com"); //automatically original owner becomes editor
 //file.addEditor("xyz@google.com");
}
 Logger.log("total count: " + count);
 
}`

Someone posted similar post here which is very useful:

Looping through multiple google spreadsheets with google scripts

Teja
  • 1
  • 1