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.
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:
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.
[email protected]
with the email address of the user who will be receiving the copied files.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.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.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: