41

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?

  • From the web interface I assume. This would be academic if you're using the client and syncing to a folder on your PC. – ale Feb 8 '13 at 3:04
  • are you wanting to just back the stuff up in that folder? or are you trying to add it to another google account? Do you need the entire contents of the folder or will just the pointers do? – William Feb 8 '13 at 20:24
  • I needed to duplicate it because I want to have different permissions on them, for this, I need to have separated environments. But using google drive for PC worked fine! – Dude2012 Feb 27 '13 at 20:13
  • Copy Folder Chrome plugin: chrome.google.com/webstore/detail/copy-folder/… – Simon Woodside Jul 10 '17 at 20:19
19

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.

  • 4
    Unfortunately for Linux users, till today Google doesn't have support for "Google Drive Application". Hence they need to use something called "grive" – iammilind Apr 9 '14 at 5:00
  • Will it re-upload the entire new folder to the web, or does it know that the contents of the folder are identical and it duplicates it without a full re-upload? – Julian Aug 1 '14 at 16:23
  • @Julian I would assume that it reuploads the whole thing. – ComputerLocus Aug 1 '14 at 17:42
  • I just confirmed that it indeed reuploads all files. Bummer. – Julian Aug 2 '14 at 5:22
  • without the app, it is also possible to right click - download the folder as zip and reupload it after unarchiving – kamidude Jan 18 '18 at 22:47
9

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
  • Super cool feature, worked perfectly even for very big folders with hundreds of sub-folders and thousands of files (some were extra large). Thank you Shunmugh! – kubusz Aug 18 '15 at 13:41
  • 3
    also adds suffix "_copy" to all the subfolders, yikes! – manas Feb 11 '16 at 20:21
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.

  • 4
    There is no "copy" option on the right-click menu. There is "make a copy". What you mean is, make a copy of all files, then highlight the copies and move them to the new folder. – Blisterpeanuts Jul 7 '17 at 2:13
  • One also needs to rename all the files after moving them to the new folder to remove the "Copy of" prefix. – Tom Sep 12 '17 at 22:25
  • This results in all the files having "Copy of" prefixed to the filenames. – Elijah Lynn Apr 26 '18 at 3:58
  • @Blisterpeanuts There is also no "make a copy" if you want to copy a folder - even if it's empty. Annoyingly so, if you want to start with a template of empty directory names – Michael Aug 12 '18 at 20:59
  • If you move a group of files with drag&drop while pressing Ctrl appears a "+" near the mouse pointer and it seems to work, but the "copied" files are just hardlinks, they have the same ID, and if you delete them will delete both that copy and the original file, needing to restore from recent activity. AFAIK this is a bug on Google Drive. – Pablo Bianchi Apr 16 at 1:59
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.

  • 6
    This requires letting the addon "View and read your email" – Michael Cole Feb 20 '17 at 17:48
  • @MichaelCole, and also other problematic permissions: manage spreadsheets, load arbitrary websites and worse of all: offline access. I recommend no one install this until the permission problems are fixed. – Guss May 13 '18 at 11:54
  • Ah.. it's the brave New post Cambridge analytica world we live in now – abbood May 13 '18 at 12:32
  • The manage spreadsheets is to add a spreadsheet log file while it is running. – Ajay Jun 15 at 17:01
2

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.

  • The main problem of this solution - aside from the obvious need to have enough space to store your entire drive contents locally, twice (both compressed and extracted) - is that if it will export all Google docs to appropriate MS OpenOffice document format, and then when you reload them you have to convert them back to Google formats and deal with all the formatting issues that this causes. – Guss May 13 '18 at 11:57
2

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

}
  • How do you run this script? Or, how do you get the input parameters? – roydukkey Jun 18 '18 at 19:00
  • It's inputs are the ID of the folder you want to copy, the ID of the folder in which you want to create the copy, and the name you want the copy to have. To get the ID of a folder, navigate to it and look at the end of the URL. It's probably something like 1jVlkj------------------------Gk3D7except all the dashes are characters. That gibberish string is the unique ID that Google assigned. Once you have the three inputs, you would call this function from another function with something like copyFolderAndContentsToFolder('superLongIdString','anotherLongIdString','NewFolderName') – Engineer Toast Jun 18 '18 at 19:13
  • This is almost perfect, but in my case I have files that are linked to different folders. So instead of copying the file, it just copies the link. – roydukkey Jun 18 '18 at 19:49
  • If you mean files that exist in multiple locations (i.e., have multiple parents), that's addressed in the post. You can copy out the countOfOtherParents++; line only and that'll do it. For my use case, I explicitly wanted those files to simply get another parent rather than creating a new copy of the file. If you mean files that act as hyperlinks that open other folders, then I didn't know you could do that. – Engineer Toast Jun 18 '18 at 20:45
  • I.E., the minimum change would be this but the "cleaner" code would be this – Engineer Toast Jun 18 '18 at 20:47
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)
  }

}
-1

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

  • 9
    That doesn't duplicate; it just creates a pointer. I tested this by doing the Ctrl-drag-n-drop of a folder to a couple of different places, then created a file in the folder, and the file is visible in every place. – ale Feb 8 '13 at 19:45
  • That's right. They call it "adding a folder" – th3an0maly Jul 16 '13 at 23:33
  • 4
    -1, doesn't work. – Pacerier Oct 31 '14 at 9:22
-1

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
    Adding essential part of the link into answer would be more helpful. – serenesat Jun 8 '16 at 9:09

protected by Community Aug 5 '16 at 2:19

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.