Table of Contents
This is a code of Google Apps Script for copying google drive folder content to other folder.
Which situation the code resolve.
Google doesn’t allow to move folder content to other folder in the browser, which is managed by other organization according to the policy of the GSUITE organization. And, Google doesn’t allow to change the content owner to the user in other organizations.
For example, XXXXX@gmail.com
can not move the folder to
shared folder managed by a GSUITE organization.
And, XXXXX@gmail.com
can not change owner to the user in
a GSUITE user.
Even in such situation, a user can read the folder content so the user can copy the content.
This script copies the folder to other folder recursively, even if the destination folder is accessible and managed by other GSUITE organization.
Why it is created.
There is a webpage to copy a folder recursively but the user in a GSUITE organization is sometimes prohibited to use the script managed by others.
How to use
Copy this script to your Google/GSUITE account and execute it.
When you copy the code, you have to update the folder IDs to yours. Folder ID appears when we opened the folders in the browsers
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
/** function myFunction() { // put source folder ID. const fromFolder = DriveApp.getFolderById('1234567ABCDEFGHIJKLMNOPQRSTUVWXYZ') // put destination folder ID. const toFolder = DriveApp.getFolderById('1234567abcdefghijklmnopqrstuvwxyz') // copy the folder content recursively. copy(fromFolder, toFolder) } function copy(fromFolder, toFolder) { // copy files var files = fromFolder.getFiles() while (files.hasNext()) { var file = files.next(); var newFile = file.makeCopy(toFolder) newFile.setName(file.getName()) } // copy folders var folders = fromFolder.getFolders() while (folders.hasNext()) { var folder = folders.next() var newFolder = toFolder.createFolder(folder.getName()) copy(folder, newFolder) } } |
I put this code on Gist.