Skip to content

Instantly share code, notes, and snippets.

@KenjiOhtsuka
Last active June 7, 2025 07:36
Show Gist options
  • Select an option

  • Save KenjiOhtsuka/d4432b6d80ad2b81ab7c965de2a8a00d to your computer and use it in GitHub Desktop.

Select an option

Save KenjiOhtsuka/d4432b6d80ad2b81ab7c965de2a8a00d to your computer and use it in GitHub Desktop.

Revisions

  1. KenjiOhtsuka revised this gist Feb 26, 2021. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions copy_files.gs
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    /**
    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 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
    @@ -17,6 +19,12 @@ 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.
    */

    function myFunction() {
  2. KenjiOhtsuka created this gist Feb 26, 2021.
    47 changes: 47 additions & 0 deletions copy_files.gs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    /**
    This is a code of Google Apps Script for copying google drive folder content to other folder.
    Google doesn't allow to move folder content to other folder 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, [email protected] can not move the folder to
    shared folder managed by a GSUITE organization.
    And, [email protected] 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.
    */

    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)
    }
    }