Skip to content

Commit

Permalink
First
Browse files Browse the repository at this point in the history
  • Loading branch information
dustintodd123 authored Sep 25, 2021
1 parent 1eab716 commit d345379
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions google-sharedrivecopy.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function startv2() {
// Code adapted from this artcile https://www.labnol.org/code/19979-copy-folders-drive
// Thank you Amit Agarwal https://github.com/labnol
// This script will copy all files and folders from the source Folder ID to a Destination Folder ID
// The Source Folder name will be created in the destination folder
// If you have been driven insane by Google Drives inability to copy a folder structure from MyDrive to a Shared drive BOOM!
//

var sourceFolderId = "0B6NGZzLlehR2dlFuRnN6SnJKN3M"; //Folder ID of the folder structure you want to copy
var targetParentFolderId = "1dABjn4OGLcdvwjBLXCDanatxNGdSNnKR"; //Target parent folder ID where the source folder will be copied

var sourceFolder = DriveApp.getFolderById(sourceFolderId); //Source Folder
var targetParent = DriveApp.getFolderById(targetParentFolderId); //Parent Folder (target)
var target = targetParent.createFolder(sourceFolder.getName()); //Create the source folder we are copying

//Here we go
copyFolder(sourceFolder, 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);
}

}

0 comments on commit d345379

Please sign in to comment.