“I receive an email with a .zip file in the attachment, can I extract its contents before Power Automate saves it into SharePoint?”
Power Automate is a great tool to help you organise email attachments. Every time you receive an email, it can check if it contains an attachment, and store it in a specific location. But for attached .zip files it’s not enough. You don’t want to just save the .zip file as you can hardly use it before you extract it. Just saving it will need a manual work to extract it – not the ideal situation. Why not let the flow do this work?
Extract the .zip file
Before you can extract the file, you must store it somewhere, e.g. in OneDrive or SharePoint. Just save it as you’d save any other attachment.
As there can be more than one attachments, check if the attachment ends with .zip in a ‘Condition’. If it does, extract it with the ‘Extract folder’ action.
It’ll ask you for the location of the file (which you know since you just created it), and a folder where it should extract the files. You can’t extract them directly into a SharePoint library, you must always create a new folder for the files, e.g. using the current date/time.
Important note: the action seems to have problem with : character in the time! I recommend using a custom format without the colon:
Move the files into a common folder
The files are now extracted, but in their own folder. That’s not a good place unless you plan using a wild folder structure. But since they’re now stored in SharePoint, you can move them anywhere you want.
Add the ‘Move file’ action and move the files using their Id in the final location. A fixed one, or a different location for each file.
Cleanup the .zip file and the folder
At this moment the flow created a lot of mess. You have the extracted files in the desired location (good!) but you’ve got also the .zip file and the empty folder (bad). Since you probably don’t want to keep all of it, you should do a cleanup.
Deleting the .zip file is the easier task – add the ‘Delete file’ action and delete it. You already have the file Id as you created the file a few steps before.
The much more complicated task is deletion of the folder. Since Power Automate doesn’t have a dedicated action to delete folders, you must use a “workaround”.
Firstly, you must get the Id of the folder as it’s not among the outputs of ‘Extract folder’.
Add an extra ‘Compose’ action to store the folder name before you extract the files. The reason is that the folder name is using the current date/time – it’d be different after the ‘Extract folder’ action.
Once you know what folder name was used, add ‘Get files (properties only)’ with a Filter query on the folder path. You already moved all the files from the folder so it’ll return just 1 item – the folder itself.
The folder itself can then be deleted using the ‘Delete item’ action. Enter the site URL, type in the library name (it won’t be in the dropdown), and use the returned Id to delete the folder.
The whole flow
When you build a Power Automate flow, you should always think about the next step to automate – you just saved the email attachment, but what about the .zip files? If you just save them then somebody will have to extract them. Why don’t you automate also this “next step”? And when the flow extracts them, somebody has to do the cleanup – what about this step? And the next one, and the next one…?