Google Drive – How to Batch Copy Folders and Files from Shared Drive

google-drive

Someone shared a batch of folders and files to me. The total number and size is quite large and I want to avoid download all of them and upload back to my Google Drive.

I have tried checking multiple items and then copy them. It will make all the selected files copied to my Drive with a - copy filename suffix. But this method wouldn't apply on folders, so folder structure is not reserved and I have to repeat the steps many times.

May I know any work around, tool or technique I can use?

Best Answer

If you're comfortable using Google Scripts the following from Amit works well for me. I've looped it with an array of folder names grabbed from a spreadsheet to deal with lots of content.

function start() {

var sourceFolder = "source";//name of the source folder
var targetFolder = "target";

var source = DriveApp.getFoldersByName(sourceFolder);
var target = DriveApp.createFolder(targetFolder);

if (source.hasNext()) {
copyFolder(source.next(), target);
}

}

function copyFolder(source, target) {

var folders = source.getFolders();
var files   = source.getFiles();

while(files.hasNext()) {
var file = files.next();
file.makeCopy(file.getName(), target);
}

 while(folders.hasNext()) {
var subFolder = folders.next();
var folderName = subFolder.getName();
var targetFolder = target.createFolder(folderName);
copyFolder(subFolder, targetFolder);
}  

}