3

I'm a superadministrator of Google Apps for Education. How do I copy all files from one user account to another without deleting the files from the first account?

I know there's a "transfer files" option, but I want to make a copy, not transfer.

2 Answers 2

2

I don't believe you can from the Admin Console. When you delete a user you have the option to transfer files to a different user, but that is obviously not what you want.

The Migrate data between Google Apps accounts support page from Google Says:

Drive files:

"Drive lets you manually download a file to your computer that you can then move to Drive in your new Google Apps account. You can also share individual documents with email addresses in your new account and then copy them. Alternatively, you can use the Drive REST API to export and import documents."

Other options:

  • Download all the users files and then upload them into the other account
  • Use Google Takeout, you'll have to be logged in as the original user and then upload them to the new user
  • Can you share the files between the users. The idea of Google Apps is to avoid having multiple copies of the same files and allowing users to collaborate
  • Check out Google Apps Script. There is a ton of drive related functions you can do with this. Here is a tutorial on Google Apps Script
1
  • Not exactly what i was asking, but seems to be the only solution. Thanks! Marked as the solution. Commented Feb 2, 2016 at 3:05
1

Let me preface my answer by saying that, for most purposes, it would be better to share the files instead of copying them. The easiest way to do this would be to add them to a folder and share that folder with the person in question. However, if you really want the target person to have their own copy of the file, completely divorced from the original, you could do it using a script like this one.

  1. To run this script, you need to be logged in as the source user, the one with the Google Drive containing the files that you want to copy.
  2. Go to script.google.com and start a new project.
  3. Copy the code below and paste it into code.gs, replacing the contents of the file.
  4. On lines 3 and 11, replace [email protected] with the email address of the user who will be receiving the copied files.
  5. If you only want to copy one folder, rather than the entire drive contents, replace FOLDER ID HERE in row 2 with the ID of the folder that you want to copy. The folder ID is the string of random characters in the URL when you open the folder in your browser.This is what a folder ID looks like
  6. Click the save button to save your project and give it a name.
  7. Under "Select function", select singleFolderCopyPaste and click the "Play" button to copy the folder you select in step 5 and its contents to the user you selected in step 4.enter image description here
  8. To copy the entire contents of your drive to the user selected in step 4, select copyPasteAll instead. Be very careful using this function, as it will copy the entire contents of your Google Drive to the target user, "your" meaning whoever is logged in and running the script.

Here's the code:

function singleFolderCopyPaste() {
  var sourceFolderId = "FOLDER ID HERE";    //enter the ID for your source folder here
  var targetUser = "[email protected]"       //enter the email address for the target user here
  var sourceUser = Session.getActiveUser();
  var sourceFolder = DriveApp.getFolderById(sourceFolderId);
  var cabinet = getCabinet(sourceFolder);
  pasteAll(cabinet, sourceUser, targetUser);
}

function copyPasteAll() {
  var targetUser = "[email protected]"       //enter the email address for the target user here
  var sourceUser = Session.getActiveUser();
  var sourceFolder = DriveApp.getRootFolder();
  var cabinet = getCabinet(sourceFolder);
  pasteAll(cabinet, sourceUser, targetUser);
}

function getFiles(folder) {
  var fileIterator = folder.getFiles();
  var fileArray = toArray(fileIterator);
  return fileArray;
}

function toArray(iterator) {
  var newArray = [];
  while(iterator.hasNext()) {
    newArray.push(iterator.next());
  }
  return newArray;
}

function getCabinet(folder) {
  var name = folder.getName();
  var folderId = folder.getId();
  var fileArray = getFiles(folder);
  var subfolders = getSubCabinets(folder);
  var cabinet = {name: name,
                 id: folderId,
                 subcabinets: subfolders,
                 files: fileArray}
  return cabinet;
}

function getSubCabinets(folder) {
  var subfolderIterator = folder.getFolders();
    var cabinetArray = [];
  while(subfolderIterator.hasNext()) {
    var subfolder = subfolderIterator.next();
    var cabinet = getCabinet(subfolder);
    cabinetArray.push(cabinet);
  }
  return cabinetArray;
}

function pasteAll(cabinet, source, destination) {
  var sourceUserEmail = source.getEmail();
  var destinationFolder = DriveApp.createFolder(sourceUserEmail);
  makeCopies(cabinet, destinationFolder,destination, source);
  destinationFolder.setOwner(destination).revokePermissions(source);
}

function makeCopies(cabinet, parentFolder,targetUser,sourceUser) {
  var folderName = cabinet.name;
  var subcabinets = cabinet.subcabinets;
  var fileArray = cabinet.files;
  var folderCopy = parentFolder.createFolder(folderName);
  var folderCopyArray = [];
  var fileCopyArray = [];
  for (var j = 0; j < fileArray.length; j = j +1) {
    var fileCopy = fileArray[j].makeCopy(folderCopy);
    DriveApp.removeFile(fileCopy);
    fileCopyArray.push(fileCopy);
    //fileCopy.setOwner(targetUser).revokePermissions(sourceUser);     //uncomment this line if you don't want the source user to have access to the copies
  }
  for (var k = 0; k < subcabinets.length; k = k + 1){
    var subfolder = subcabinets[k];
    makeCopies(subfolder, folderCopy, targetUser, sourceUser);
  }
  DriveApp.removeFolder(folderCopy);
  folderCopyArray.push(folderCopy);
  //folderCopy.setOwner(targetUser).revokePermissions(sourceUser);     //uncomment this line if you don't want the source user to have access to the copies
}

Notes:

  • The recipient of the files will see a new folder in the root of their drive. The name of this folder is the source user's email.
  • The recipient is the owner of the new folder, and the sender has no access to the new folder itself. However, the sender is still designated as the "owner" of the files in the folder. These files are not located in the sender's folder tree in Google Drive, but the still take up storage space. They can be found via a direct link, or by using the Search box.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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