53

I need to duplicate an entire folder on my Google Drive once a week. There are about 25 files in the folder. What is an easy way to do this?

Andrew Lott
  • 2,531
  • 4
  • 25
  • 36
Dude2012
  • 641
  • 1
  • 5
  • 4

9 Answers9

24

If you are using the Google Drive application on your PC you can copy and paste the folder in the Google Drive directory, and this would copy it. I do not believe it is possible to do this from the web application.

ComputerLocus
  • 4,163
  • 2
  • 27
  • 44
12

Have written an App Script just to address this problem. You can copy any folder contents as well as the structure in it. Script will help eliminate the need of Google Drive desktop app. By adding triggers you can even automate the process.

GDrive Copy Folder Structure/Content Script

Copy Folder Structure in Google Drive

Please note :

  • this also adds suffix _copy to all subfolders
  • The folder_you_want_copied_copy is in the highest parent hierarchy of your Google Drive, so if you copied a subfolder of your drive, it will bubble up to the highest level when copied
7

Very late answer for the OP, and I think not even possible at the time of asking, but this is what I do today :

  1. Select the folder I want to duplicate.
  2. Secondary click on it, and then choose "Download" from the pop-up menu
  3. Have my browser save the zipped archive to a temporary directory
  4. Extract the folder from the archive, and give it a new name
  5. Back in Drive; click the big blue New button, and select "Folder upload" from the drop down menu.
  6. Back in my computer; grab the newly named folder and drag it back into Drive.
  7. Flush the toilet

Note : This is a solution when you have a lot of little files and sub-folders that together make for a smallish compressed file. It's usefulness decreases as the total compressed file size increases.

Martin Bramwell
  • 604
  • 7
  • 6
5

If you are in the Google Drive web interface...

  1. Create a new folder and name it what you want.

  2. Go into the Pre-existing folder, select all the files, right click and hit copy.

  3. Select all the copies, right click and hit move to. Select the New Folder.

Note that this method will not work if the folder you wish to copy has subfolders.

Stevoisiak
  • 3,925
  • 10
  • 43
  • 77
Brandon
  • 59
  • 1
  • 1
4

I prefer to abstain from allowing third parties access to my Drive unless I have to so, like Lucky 711, I wrote my own script. I leave it here for future Google results adventurers. It will copy the folder and all its contents. For my use case, I wrote it to handle files with multiple parents by just adding the copied folder as a new parent. If you don't want that, drop the "Count the parents that aren't this parent" part.

function copyFolderAndContentsToFolder(folderToCopyId, newParentFolderId, newFolderName) {

  var folderToCopy = DriveApp.getFolderById(folderToCopyId);
  var newParentFolder = DriveApp.getFolderById(newParentFolderId);

  // Create the copy of the folder
  var newFolder = newParentFolder.createFolder(newFolderName);

  // Copy all the files in that folder
  var files = folderToCopy.getFiles();
  while (files.hasNext()) {
    var file = files.next();

    // Count the parents that aren't this parent
    var countOfOtherParents = 0;
    var parents = file.getParents();
    while (parents.hasNext()) {
      var parent = parents.next();
      if (parent.getId() !== folderToCopyId) { countOfOtherParents++; }
    }

    // If it's unique, then copy it. Otherwise, just add it to the new parent.
    if (countOfOtherParents == 0) {
      file.makeCopy(file.getName(),newFolder);
    } else {
      newFolder.addFile(file);
    }

  }

  // Copy all the subfolders in that folder
  var folders = folderToCopy.getFolders();
  while (folders.hasNext()) {
    var folder = folders.next();
    copyFolderAndContentsToFolder(folder.getId(), newFolder.getId(), folder.getName());
  }

}

For reference, if you want to create new copies of files with multiple parents rather than just adding the new folder as another parent, the shorter code would look like this:

function copyFolderAndContentsToFolder(folderToCopyId, newParentFolderId, newFolderName) {

  var folderToCopy = DriveApp.getFolderById(folderToCopyId);
  var newParentFolder = DriveApp.getFolderById(newParentFolderId);

  // Create the copy of the folder
  var newFolder = newParentFolder.createFolder(newFolderName);

  // Copy all the files in that folder
  var files = folderToCopy.getFiles();
  while (files.hasNext()) {
    var file = files.next();
    file.makeCopy(file.getName(),newFolder);
  }

  // Copy all the subfolders in that folder
  var folders = folderToCopy.getFolders();
  while (folders.hasNext()) {
    var folder = folders.next();
    copyFolderAndContentsToFolder(folder.getId(), newFolder.getId(), folder.getName());
  }

}
Engineer Toast
  • 393
  • 2
  • 16
3

You can use the "Copy Folder" add-on for Google Spreadsheets:

  1. create a Google Spreadsheet
  2. click on Add-ons > Get add-ons and add the 'Copy Folder' add-on`
  3. select the folder you want to copy
  4. done

See the video tutorial.

Or, this chrome web store Google App Script can be used to achieve this result. This one does not require the creation of a Google Spreadsheet.

Ajay
  • 103
  • 4
abbood
  • 1,219
  • 5
  • 19
  • 36
1

I use multiple machines and don't want to put the drive app on all of them so I have written the below script to copy on the site. It’s ugly and basic but it works. It only copies a folder and its files, not sub folders. I am sure there is room for improvement, so feel free to take this and improve it, but I hope it’s at least helpful from the start.

Per a comment below, this is a Google Apps Script. The way to use it is to open the Google scripting app, then copy and past all of the code into a blank script. After that click the publish option on the Menu, then select deploy as web app. You can then click the Latest code link or copy and paste the URL into your browser. Then, you will find a box where you can type the folder that you want to copy, and the copy button. That should create a copy of the folder you have named, and a copy of all of the files within.

Note: it will not copy sub-folders, just the files.

function doGet()
{
  // Build UI
  // Create UI object
  var copyUI = UiApp.createApplication();
  // Create Input box referenced later by the name explicitly set below
  var userInput = copyUI.createTextBox().setName("textbox1");
  //create button
  var enterButton = copyUI.createButton("copy");
  // add all objects to UI object
  copyUI.add(userInput).add(enterButton);

  //Create clicke event handeler and add input field to handeler
  var clickHandler = copyUI.createServerHandler('onClick')
  .addCallbackElement(userInput);

  // add handelrer to the copy button
  enterButton.addClickHandler(clickHandler);

  // instantiate GUI
  return copyUI;
}


function onClick(e)
{
  // call currently active application/gui
  var app = UiApp.getActiveApplication();

  //Pass in the value of the e paramater named 'textbox1'
  var input = e.parameter.textbox1;

  // log value passed in from user input
  //Logger.log(input);

  // perform file copy
  CopyFile(input);
}


function CopyFile(filename)
{
  // declaire variables
  var newFolder_String;
  var newFolder;
  var originalFolder;
  var fileArray;
  var loopCount;
  var arrayLength;
  var newFile;
  // get original folder id
  originalFolder = DocsList.getFolder(filename);
  Logger.log(originalFolder.getId());


  // create new "copy" folder using: createFolder(<filename>_copy)
  newFolder_String = filename + "_Copy";
  Logger.log(newFolder_String);
  newFolder = DocsList.createFolder(newFolder_String);

  // get folders and files from original file using: 
    //   getFiles() from original file into an array
  fileArray = originalFolder.getFiles();

  // Copy files into folder:
  arrayLength = fileArray.length;
  loopCount = 0;

  // looping through array of file
  for (loopCount = 0; loopCount < arrayLength; loopCount++)
  {
    // create file copies using: file[i].makeCopy() and newFile.addToFolder(CopyFolder)
    newFile = fileArray[loopCount].makeCopy();
    Logger.log(newFile.getName());
    newFile.addToFolder(newFolder)
  }

}
jonsca
  • 1,732
  • 18
  • 23
  • 44
Lucky 711
  • 11
  • 1
0

This is a very good Google Script Macros app: https://script.google.com/macros/s/AKfycbxbGNGajrxv-HbX2sVY2OTu7yj9VvxlOMOeQblZFuq7rYm7uyo/exec

with real time logs and folder selector.

-1

To duplicate a folder drag & drop it on another folder holding CTRL button.

aborruso
  • 151
  • 6