This script helps you copy a folder's entire structure and its files, creating multiple replicas within a single specified destination folder, with flexible naming options.
Make a Copy of Your Script Sheet:
Give the new copy a descriptive name (e.g., "Project X - Folder Replicator"). This creates a fresh, identical spreadsheet, including the script and its setup.
Open the Newly Copied Sheet: Close the original sheet if you wish, and open the new copy you just created.
Quick Script Verification & Initial Authorization (Optional):
The very first time, Google will prompt you for authorization. Follow the steps to grant permissions. This is a standard security step.
Close the Apps Script editor tab when done.
Refresh the Copied Sheet: Refresh your browser tab for the copied Google Sheet (F5 or Ctrl+R/Cmd+R). After it reloads, the custom menu item Folder Tools should appear in the menu bar.
Proceed to the "Setup" section below. The Setup and Log tabs will be created automatically when you first interact with the script.
Navigate to "Setup" Tab: Click on the Setup tab at the bottom of the spreadsheet (if it's not visible, it will be created automatically when you first run the script via the "Folder Tools" menu).
You'll see labels in cells A1, A2, C1, and D1 guiding you where to enter information.
Source Folder ID (Cell B1):
Open the Google Drive folder whose contents you want to copy (this is your source folder).
In your browser's URL bar, find the ID of this folder. It's the long string of characters after "folders/".
Example URL: https://drive.google.com/drive/folders/abcdef1234567890_this-is-the-id_xyz
Copy only this ID.
Paste the ID into cell B1 of the "Setup" tab.
Single Destination Folder ID (Cell B2):
Open the Google Drive folder where you want all the new replica copies to be created (this is your destination folder).
Copy the folder ID from the URL (the string after "folders/").
Paste this ID into cell B2 of the "Setup" tab.
Important: All your new replicas will be created inside this one folder.
Add Date to Replicas (Cell C2):
Decide if you want a date and replica number added to the name of the new top-level replica folders.
In cell C2, type Yes if you want the format YYYY-MM-DD-ReplicaNumber-OriginalFolderName (e.g., 2025-07-30-1-MyProject).
In cell C2, type No if you want the format ReplicaNumber-OriginalFolderName (e.g., 1-MyProject).
This input is not case-sensitive (e.g., "yes", "YES", "No", "no" all work).
Number of Replicas to Create (Cell D2):
In cell D2, enter the number of duplicate folders you want to create within your specified destination folder.
For example, if you enter 3 in D2, the script will create three separate copies of your source folder's contents, all placed inside the folder whose ID is in B2.
If this cell is left empty, or contains an invalid number, the script will not run and will show an error, prompting you to enter a valid positive number.
Access the Custom Menu: In the Google Sheet, go to the Folder Tools menu in the top ribbon (this menu is created automatically when you open the sheet).
Start Replication: Click on Create Multiple Replicas in One Destination.
Authorization (First Run in This Specific Sheet): The very first time you attempt to run the script in a particular spreadsheet (whether it's a new setup or a freshly copied one), Google will ask for your permission to access your Drive and Spreadsheet. Follow the prompts carefully to authorize it. This is a standard security step and only needs to be done once for this specific copied sheet.
Monitor Progress:
The script will show an alert when it starts and completes (or if there are errors).
The Log tab will automatically update with a detailed, real-time log of every file and folder being processed, including any errors. This is very helpful for larger operations.
Permissions: Ensure the Google account you are using has Manager or Content Manager access to both the source folder and the single destination folder to avoid permission errors during copying and folder creation.
Time to Complete: Depending on the number of files, subfolders, and replicas, the script can take some time to complete. Please be patient.
Unique Naming for Replicas: When "Add Date to Replicas" is set to "Yes" or "No", each top-level replica folder will have a unique name including its replica number (e.g., 2025-07-30-1-MyFolder, 2025-07-30-2-MyFolder or 1-MyFolder, 2-MyFolder). If you run the script multiple times with the same settings on the same day, Google Drive might automatically add an extra (1), (2) to the end of the replica's name if it detects a clash for the exact same string you're trying to create.
Idempotency for Subfolders/Files: For files and subfolders within each newly created replica folder, the script is smart! If you were to somehow run the copy process into an already partially filled replica folder (e.g., if a previous run failed mid-way into one replica), the script will intelligently skip items that already exist within that specific replica's subfolders to prevent duplicates and save time.