Copying files and folders from a personal Google Drive to a Shared Google Drive (aka Team Drives) using Google Apps Script
- Copy app script
- In setting enable
Show appscript.json ...
- Add
"oauthScopes": ["https://www.googleapis.com/auth/drive"]
on the end of theappscript.json
file. - Edit
sourceFolderId
andtargetSharedDriveId
based on your Google Drive web app URL linkshttps://drive.google.com/drive/folders/dfsfsdt453rfds45341243-53425
->dfsfsdt453rfds45341243-53425
function copyFolder(sourceFolder, targetFolder, onlyPrintFiles = true) {
// Copy the folders
if (onlyPrintFiles) {
Logger.log('Only print file names');
}
copyAllFilesInFolder(sourceSubfolder, newFolder, onlyPrintFiles);
var sourceSubfolders = sourceFolder.getFolders();
while (sourceSubfolders.hasNext()) {
var sourceSubfolder = sourceSubfolders.next();
Logger.log(
Creating folder: ${sourceSubfolder.getName()}
)var newFolder = targetFolder.createFolder(sourceSubfolder.getName());
copyFolder(sourceSubfolder, newFolder, onlyPrintFiles); // Recursive call for subfolders
}
}