November 20, 2024

SharePoint: Issue extracting a zip with empty folders

Let’s start with a practical example to demonstrate this issue. You have a pre-defined structure for your projects, and you want, when you create a new project automatically. Microsoft Flow can help by creates the folder structure for you but, so you zip all the folders and files that contain the basic structure.

So far so good, Flow enables us to unzip a file to a specific location that can be OneDrive or SharePoint, and we can even rename the folder to fit our project code and naming convention. But when the flow runs you notice that some folders are missing. The folders that didn’t contain any files.

You could put a text file in each folder, but this would be an ugly solution, so let’s try to find a better one.

The solution

TL;DR Solution is not to have a zip file but a folder that you copy from the SharePoint template to your desired SharePoint instance.

SharePoint enables us to copy entire folders from one instance to another so we can take advantage of that to create our templates and copy them to the destination folder. These can be empty, and Flow copies them regardless, contrary if you use a zip file where Flow copies only the folders with content.

Want an example?

The example has two parts:

  1. SharePoint to centralize your templates. I consider this a best practice, so if you’re not doing it, take this time to do so.
  2. Flow to demonstrate the copy of the folders

Centralize your information

First, I recommend creating a SharePoint site with all your templates. Just dump folders with (or not) files and, if you have zip files, uncompress them there and follow the steps defined further.

You’ll get a lot of advantages by doing so:

  1. You can share with other people and allow for collaboration on the templates.
  2. There’s only a Single Source of Truth, so other people in the organization always know where to find the templates
  3. Better automation. Since the information is shared, different departments can create their Flows based on the central repository, saving time for everyone.

Step 1 – Create the site

Just go to “Create a new Site” and pick the type. In our example, we’ll select “Communication.”

Step 2 – Add the templates

Copy the folders into the “Documents” area. I recommend creating different folders for each context, but I’ll leave it up to you how to decide what makes sense.

Step 3 – (Optional) add the necessary folders

Add the subfolders. In this case, I created empty folders to ensure that I can simulate the problem.

Don’t believe me?

Ok, let’s continue now that we trust each other :).

Create the flow

This flow is quite simple. I’ll use it to demonstrate the concept, but then you can create your paths and rename the folders.

Step 1 – Add a new flow

Just go to flow.microsoft.com and create a new Flow. Add a “copy folder“ action and pick:

  1. Your source. A SharePoint template folder either that you created in previous steps or that already exists.
  2. The destination folder. Since this instance only contains templates, you’ll need to select a different SharePoint instance.
  3. What to do when a folder exists. Define your strategy between the options.

Step 2 – Run the flow

You’ll get the following new folders in SharePoint (I’m using the same source and destination).

All is looking really good. We have a project folder.

If you go to the “Business Plan”, for example, you can see that Flow copies all folders, even the empty ones.

Here you go. Simple and straightforward solution.

Final thoughts

Ideally, we would have zip files that could save us some space and contain all the data. I prefer this solution because I can easily change, add new files, and change the folder structure without needing to create a new zip. Besides space, there’s no real advantage of using zip files and there are a lot of advantages to just use plain folders.

Have a suggestion of your own or disagree with something I said? Leave a comment or interact on Twitter and be sure to check out my articles on SharePointFlow, or problem solved tutorials.

Featured Image by Kelly Sikkema on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon