Transfer Google Drive data between accounts using Google scripts

I had a number of important files on a google drive account administered by other organization.  Now that I’ve completed the job, I believe that my account will be deleted in the near future, and I’m hoping to move my files to my new google drive account administered by me or my other Google account.

If you have a operating system that support Google drive Application which in case Windows and Mac are then you can do it just by sharing the files with other account(where you want to transfer files) but you are still not owner of those shared files but using a Google drive application you can copy that shared folder to other folder and you are done. this process is time consuming and also will not work with operating systems which don’t have Google Drive application. In my case using Ubuntu I had no possible to way to do it, but fortunately I found a great solution to this problem.

I’ll describe following steps to make this happen.

Using Google Drive web interface:

  1. Create a new folder and name it what you want.
  2. Go into the Pre-existing folders/files, select all the files, and move these files to created folder.
  3. Share that folder with destination account(where files need to transfer).
  4. Login to destination account and in Google drive interface you will see shared folder under “Share with me” link.
  5. In Google Drive, theres no easy way to duplicate a folder. It is possible to make a copy of individual files but theres no command for creating duplicate folders that are a mirror of another folder or are shared. but fortunately we can solve this problem by Google App Scrips. Bellow is the piece of JavaScript code which can help you to duplicate nested folder in drive.
  6. Visit Google app scrips page and click start scripting and paste the following code.
function duplicate() {
  var sourceFolder = "Folder";
  var targetFolder = "FolderCopy";
  var source = DriveApp.getFoldersByName(sourceFolder);
  var target = DriveApp.createFolder(targetFolder);
  if (source.hasNext()) {
    copyFolder(, target);
function copyFolder(source, target) {
  var folders = source.getFolders();
  var files   = source.getFiles();
  while(files.hasNext()) {
    var file =;
    file.makeCopy(file.getName(), target);
  while(folders.hasNext()) {
    var subFolder =;
    var folderName = subFolder.getName();
    var targetFolder = target.createFolder(folderName);
    copyFolder(subFolder, targetFolder);

To run this code successfully you will need to provide Google drive permission and you can run above code. from list of function select duplicate function and click run. this will copy source folder and files to destination folder.