Azure Logic Apps: SharePoint Online | Unzip the Zips


The ask, query and return the .zip files found at the root of a SharePoint Online (SPO) document library, then unzip their contents to a series of regular folders.

Once upon a time, it was necessary to zip files and save space, but these days, with the cloud, the juice really isn’t worth the squeeze. Unfortunately, there are already hundreds of .zip files from years of this behavior and because SPO search results don’t include their zipped content, the business now wants these compressed files unzipped:

Figure 1 - SharePoint Online document library with .zip files.
Figure 1 – SharePoint Online document library with .zip files.

At a high-level, this flow could run on a schedule, allowing it to make multiple passes, catching .zip files it may have missed on an earlier run. Once triggered, there are 4 flow variables necessary for a successful run:

(1) Initialize tempObj variable of type Object. This will be used to store response objects during the iteration of queried SPO .zip files.

(2) Initialize nameFolder variable of type String. As the name suggests, this variable will store the name of the extracted folder within the loop.

(3) Initialize pathSource variable of type String. To perform the unzip, the extraction action will need the SPO path of the .zip file within the loop.

(4) Initialize pathTarget variable of type String. During the extraction action, the flow will need to specify where to unzip the compressed files.

Now, with the flow variables initialized, add an action to Get files (properties only), which will return an array of SPO library items. Worth noting, the export of this action could return non-zipped files. As a precaution, add a Filter array action and use the Get files (properties only) action’s output as input. This ensures only .zip files are iterated in the loop:

Figure 2 - Azure Logic App visual view.
Figure 2 – Azure Logic App visual view.

Taking a step back, an optional step is to create two flow parameters of type String. Here, flow parameters act as global variables:

Figure 3 - Azure Logic Apps flow parameters.
Figure 3 – Azure Logic Apps flow parameters.

If choosing to use flow parameters, then they could be added to the Get files (properties only) action.

Also worth noting, depending on the size of the library, it may be necessary to select and open the Advanced parameters and add filter conditions, slicing the dataset:

Figure 4 - Azure Logic Apps action to Get files (properties only) from SharePoint Online.
Figure 4 – Azure Logic Apps action to Get files (properties only) from SharePoint Online.

The output of the Get files (properties only) action becomes the input for the Filter array action. Per the requirements, this flow only needs to process .zip files, so filter on the “{FilenameWithExtension}.” Only return files that end with .zip:

  • item()?[‘FilenameWithExtension’]
Figure 5 - Azure Logic Apps action to Filter array, returning only file with a .zip extension.
Figure 5 – Azure Logic Apps action to Filter array, returning only file with a .zip extension.

So far, the flow has queried a SPO document library and returned an array of files. That array of files is then filtered to find only the files with a .zip extension. This filtered array output is now provided as input to the For each loop to process each zipped file.

Take the Current item of the loop and assign it to the tempObj flow variable. This variable will now contain a JSON object representing each .zip file as the For each loop iterates. In each loop, parse the values for flow variables nameFolder and pathSource, then assign a value to pathTarget:

Figure 6 - Azure Logic Apps For each loop to iterate array of .zip files.
Figure 6 – Azure Logic Apps For each loop to iterate array of .zip files.

Parse and assign values to nameFolder and pathSource, respectively:

  • variables(‘tempObj’)[‘{Name}’]
  • variables(‘tempObj’)[‘{FullPath}’]
Figure 7 - Set variable action for nameFolder flow variable.
Figure 7 – Set variable action for nameFolder flow variable.
Figure 8 - Set variable action for pathSource flow variable.
Figure 8 – Set variable action for pathSource flow variable.

Parse and concatenate a value for pathTarget, then use the nameFolder to specify the target for the Extract folder action:

  • variables(‘tempObj’)[‘{Path}’]
Figure 9 - Set variable action for pathTarget flow variable.
Figure 9 – Set variable action for pathTarget flow variable.
Figure 10 - Azure Logic Apps action to Extract folder, unzipping SharePoint Online files to a target library folder.
Figure 10 – Azure Logic Apps action to Extract folder, unzipping SharePoint Online files to a target library folder.

Finally, save and run. If the same directory was chosen, then the SPO library should now list the unzipped content:

Figure 11 - SharePoint Online library with unzipped folders.
Figure 11 – SharePoint Online library with unzipped folders.

Conclusion:
For those with Power Automate cloud flow experience, they should feel pretty comfortable with Azure Logic Apps. ..

“My silences had not protected me. Your silence will not protect you.”

Audre Lorde

#BlackLivesMatter

Leave a comment