Copy this into Google Apps script (script.google.com), doesn't matter on which account.
Copy this into Google Apps script (script.google.com), doesn't matter on which account.Click on the source folder, click Share, and then advanced. Copy the link's key into the "..." for the source.
Click on the source folder, click Share, and then advanced. Copy the link's key into the "..." for the source.Do the same for the destination folder.
Do the same for the destination folder.Run it how many times you want.
function start() {
var originFolder = DriveApp.getFolderById("..."); var destination = DriveApp.getFolderById("...");
copyFolder(originFolder, destination);
}
function copyFolder(source, target) {
var folders = source.getFolders(); var files = source.getFiles();
while(files.hasNext()) { var file = files.next(); var dest = target.getFilesByName(file.getName()); if (dest.hasNext()) { // skip because file exists Logger.log('skipping copy for ' + file.getName() + ' because it exists.'); continue; }
Logger.log("copying file: " + file.getName()); file.makeCopy(file.getName(), target);
}
while(folders.hasNext()) { var subFolder = folders.next(); var folderName = subFolder.getName();
var dest = target.getFoldersByName(folderName); var targetFolder; if (!dest.hasNext()) { Logger.log('creating folder ' + folderName); targetFolder = target.createFolder(folderName); } else { targetFolder = dest.next(); } copyFolder(subFolder, targetFolder);
}
}
Run it how many times you want.
function start() {
var originFolder = DriveApp.getFolderById("...");
var destination = DriveApp.getFolderById("...");
copyFolder(originFolder, destination);
}
function copyFolder(source, target) {
var folders = source.getFolders();
var files = source.getFiles();
while(files.hasNext()) {
var file = files.next();
var dest = target.getFilesByName(file.getName());
if (dest.hasNext()) {
// skip because file exists
Logger.log('skipping copy for ' + file.getName() + ' because it exists.');
continue;
}
Logger.log("copying file: " + file.getName());
file.makeCopy(file.getName(), target);
}
while(folders.hasNext()) {
var subFolder = folders.next();
var folderName = subFolder.getName();
var dest = target.getFoldersByName(folderName);
var targetFolder;
if (!dest.hasNext()) {
Logger.log('creating folder ' + folderName);
targetFolder = target.createFolder(folderName);
} else {
targetFolder = dest.next();
}
copyFolder(subFolder, targetFolder);
}
}