In today’s fast-paced business world, efficiency is key. As a business owner and consultant, I’ve learned that the difference between success and stagnation often lies in the small details – like how we manage our digital workspace. One of the most time-consuming tasks I’ve encountered is manually creating folder structures in Google Drive, especially when dealing with repetitive projects or content creation processes.
But what if I told you there’s a way to automate this tedious task? A method that not only saves time but also ensures consistency across your projects? Enter Google Apps Script – a powerful tool that can transform the way you interact with Google Drive.
In this article, I’ll share a script I’ve developed that automatically unzips, .zip files and creates folder structures in Google Drive. Whether you’re a business professional looking to streamline your workflow or a curious mind interested in the possibilities of automation, this guide will walk you through the process, explain the code, and showcase real-world applications.
Why Automate Folder Creation?
Before we dive into the technical details, let’s consider why this automation is so valuable:
- Time Savings: Creating folders manually can take anywhere from 5 to 10 minutes per project. This might not seem like much, but it adds up quickly when you’re handling multiple projects daily.
- Consistency: With automation, you ensure that every project follows the same folder structure, making it easier for team members to find and organize files.
- Reduced Human Error: Automation eliminates the risk of forgetting to create essential folders or mistyping folder names.
- Scalability: As your business grows, this automation scales with you, handling increased workload without additional time investment.
- Integration Potential: The script can be integrated with other tools like Make.com (formerly Integromat) to create even more powerful workflows.
Understanding the Script
Now, let’s break down the script and understand its components. Don’t worry if you’re not a developer – I’ll explain each part in simple terms.
The Main Function
The heart of our script is the extractZipAndCreateFolders function. Here’s what it does:
- It takes three parameters:
- fileId: The ID of the zip file in Google Drive
- destinationFolderId: The ID of the folder where we want to create our new structure
- newFolderName: (Optional) A custom name for the main folder
- It unzips the file and creates a folder structure based on the contents of the zip file.
- It handles errors gracefully, ensuring that if one file fails, the rest of the process continues.
- It returns a JSON string with detailed information about the created folders and files.
Helper Functions
The script includes several helper functions that make the main function work:
- createFolderStructure: Creates the necessary folders based on the file paths in the zip.
- getFolderIdFromPath: Retrieves the ID of a folder given its path.
- getUniqueFolderName: Ensures that folder names are unique by appending a timestamp if necessary.
The script also includes several security measures to ensure safe usage when deployed as a web app:
- API Key Authentication: Ensures only authorized requests are processed.
- Rate Limiting: Prevents abuse by limiting how frequently the script can be called.
- Input Validation: Checks that the provided file IDs are in the correct format.
- File Access Verification: Confirms that the script has access to the specified files.
Setting Up Your API Key
At the top of the script, you’ll find a CONFIG object. Replace ‘YOUR_SECRET_API_KEY’ with your actual API key:
// Configuration const CONFIG = {
API_KEY: 'YOUR_SECRET_API_KEY' // Replace with your actual API key
};
Full Google Apps Script To UnZip .Zip Files
Publishing Your Script for External Use
To use this script with external tools like Make.com, you need to publish it as a web app. Here’s how to do it:
- Open your Google Apps Script project.
- Click on the “Deploy” button at the top right of the script editor.
- Select “New deployment” from the dropdown menu.
- In the “New deployment” window:
- Click the gear icon next to “Select type” and choose “Web app”.
- Under “Execute as”, select your account.
- Under “Who has access”, choose “Anyone” if you want it to be publicly accessible, or “Anyone with Google Account” for more restricted access.
- Click “Deploy”.
- Google will ask you to authorize the app. Review the permissions and click “Authorize”.
- You’ll receive a URL for your web app. Save this URL – you’ll need it to call your script from external tools.
Using the Script with Make.com
Now that your script is published as a web app, you can call it from Make.com (or any other tool that can make HTTP requests). Here’s how to set it up in Make.com:
- In your Make.com scenario, add a “HTTP” module.
- Set the method to “POST”.
- In the “URL” field, paste the web app URL you received when publishing your script.
- In the “Body” section, select “Raw” and set the content type to “JSON (application/json)”.
- In the body, include your parameters like this:
{
"apiKey": "YOUR_SECRET_API_KEY",
"fileId": "your_zip_file_id_here",
"destinationFolderId": "your_destination_folder_id_here",
"newFolderName": "Your New Folder Name"
}
Important: In the Make HTTP module settings, click on “Show advanced settings”. Set both “Follow redirect” and “Follow all redirects” to “Yes”.
This last step is crucial for handling Google’s security redirects when accessing Apps Script web apps.
In the subsequent modules of your Make.com scenario, you can parse the JSON response from the script and use the information as needed.
Remember to keep your API key secure and not share it publicly. Also, update your script’s authorization settings in Google Apps Scripts if you make changes to the code after publishing. You may need to create a new deployment for significant changes.
By following these steps, you’ve now made your Google Apps Script accessible to external tools, greatly expanding its potential for automation and integration in your workflows.
Troubleshooting
If you encounter issues when calling the script from Make.com, here are some things to check:
- Ensure the API key in your Make.com request matches the one in your script.
- Double-check that you’ve enabled both “Follow redirect” and “Follow all redirects” in the HTTP module settings.
- Verify that your Google Apps Script is properly deployed as a web app and that you’re using the correct URL.
- Check the execution logs in your Google Apps Script project for any error messages.
Real-World Applications
Let’s look at some practical ways this script can be used:
1. Content Creation Workflow
As someone who manages content creation, I use this script to set up project folders for each new piece of content. Here’s how it works:
- I have a template zip file with folders for research, drafts, media, and final output.
- When starting a new project, I run the script, which creates a new folder structure based on this template.
- The script returns the folder IDs, which I can then use to direct my team (or AI assistants) to the correct locations for their work.
This process ensures consistency across all our content projects and saves valuable time in project setup.
2. Production Run Management
For my e-commerce business, Oh Crap (Australia’s #1 non-plastic compostable dog poop bag), I use this script to set up folders for each production run:
- The zip template includes folders for order info, invoices, artwork, and logistics.
- Running the script creates this structure instantly, ready for all related documents.
- The returned folder information can be immediately added to our project management system, allowing team members to start work without delay.
3. Client Project Setup
As a consultant, I use this script to quickly set up project spaces for new clients:
- The zip template includes standard folders like contracts, communications, deliverables, and invoices.
- Running the script creates a consistent structure for each new client.
- This ensures that all client information is organized in the same way, making it easier to manage multiple clients efficiently.
Setting Up and Running the Script
To use this script, you’ll need to follow these steps:
- Open Google Apps Script by going to script.google.com.
- Create a new project and paste the full script into the editor.
- Save the project and give it a name.
To test the script, you can use the testExtractZipAndCreateFolders function:
** Remember to replace the fileId and destinationFolderId with your own Google Drive file IDs.
Add this to the bottom of your script in the Google Apps Script coding tool, and run the function with the ID’s you want to test it with.
Integration with Other Tools
This script becomes even more powerful when integrated with automation tools like Make.com. Here’s a basic example of how you might use it:
- Set up a new scenario in Make.com.
- Use a trigger module (e.g., “Watch Folder” in Google Drive).
- When a new zip file is detected, call the Google Apps Script using the “Google Apps Script” module.
- Use the returned JSON data to update your project management tool or notify team members.
or
Call this script from a make.com scenario (automation) to create all your content folders and add the relevant links back to your content planning sheet and project management system. Then let your AI agents add their work to the folders you have created.
Conclusion
Automating folder creation in Google Drive might seem like a small thing, but it’s these small efficiencies that add up to significant time savings and improved workflows. This script is just one example of how a little bit of code can make a big difference in your daily operations.
As businesses continue to digitize and automate, tools like this will become increasingly valuable. Whether you’re managing content creation, e-commerce operations, or client projects, finding ways to streamline repetitive tasks is crucial for scaling your business efficiently.
I encourage you to try this script in your own workflows. Experiment with different folder structures, integrate it with your existing tools, and see how it can improve your productivity.
What’s Next?
This script is just the beginning. There are countless other ways to automate and optimize your Google Drive workflows. In future posts, we’ll explore more advanced techniques, like automatically creating and populating Google Docs or Sheets, or integrating with other Google Workspace apps.
What automation challenges are you facing in your business? How could tools like this help you work more efficiently? I’d love to hear your thoughts and experiences. Leave a comment below or reach out on social media to continue the conversation.
Remember, in the world of business automation, “Marketing is a commodity, the process is priceless.” Let’s keep refining our processes and unlocking new levels of productivity together.
0 Comments