cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AndreRadtkeKIT
New Member

Unzip zip archives rename target files and delete original zip archive then

Hey folks,

 

I am totally new to power automate (Flow) and I am dealing with the following requirement and struggle how to approach:

 

I need a folder to be checked (event triggered) if there are is are new .zip files created in it. If there are new .zip files, the flow has to grab every .zip file one by one and extract it´s content to the same folder and rename the extracted file(s) to the format yyyy-mm-dd-hh-mm-ss-originalfilename.ext. Afterwards the source .zip file is no longer needed and has to be deleted (alternatively it could be moved to a temp folder), then the next .zip file has to be gone through the same process of being extracted, files renamed with date in it´s name and the source .zip has to be deleted until every .zip in the folder got deleted and their files have been extracted and renamed.

 

I tested with two actions "when a file is created" and "extract archghive to folder" but if I test the flow nothing happens the test screen has a circle of death and nothing happens no error nothing: 

AndreRadtkeKIT_1-1617812510396.png

 

 

5 REPLIES 5
DamoBird365
Super User
Super User

Hi @AndreRadtkeKIT 

 

Quite a fun one this.  I have a folder call ZIPs on my OneDrive and if I drop a zip into it, it will extract, delete and then rename the files in a new folder called ZIPs/Renamed.  I have included a Copy/Paste solution for you below.  You can copy and paste this into your Cloud Flow - all you need is the when file is created in One Drive trigger and update the Compose Action with the name of your Folder for Zips that needs monitored (first compose) and also List Files in Folder Path as it needs a folder ID.  Make sure you create a Renamed folder too.  

 

The solution looks like follows:

DamoBird365_0-1617823220396.png

 

Which will be horrible to look at as it is a large solution, but copy this to your clipboard, click on add action and "My Clipboard" and paste and select the solution to import.

 

{"id":"5cd58a61-043a-49fa-b09a-69a3-65696bea","brandColor":"#8C3900","connectionReferences":{"shared_onedriveforbusiness":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness/connections/shared-onedriveforbu-5a107753-9d6f-4fbf-957e-72c6-987acc35"}}},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"SolutionByDamoBird365-UnzipAndRenameFilesWhenZipCreatedInOneDrive","operationDefinition":{"type":"Scope","actions":{"RootFolderPathOneDrive(PleaseUpdatePath)":{"type":"Compose","inputs":"/ZIPs","runAfter":{}},"Condition":{"type":"If","expression":{"contains":["@triggerOutputs()?['headers/x-ms-file-name']",".zip"]},"actions":{"Extract_archive_to_folder":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"ExtractFolderV2","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"source":"@{outputs('RootFolderPathOneDrive(PleaseUpdatePath)')}/@{triggerOutputs()?['headers/x-ms-file-name']}","destination":"@outputs('RootFolderPathOneDrive(PleaseUpdatePath)')","overwrite":true},"authentication":"@parameters('$authentication')"},"runAfter":{}},"Delete_file":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"DeleteFile","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"id":"@triggerOutputs()?['headers/x-ms-file-id']"},"authentication":"@parameters('$authentication')"},"runAfter":{"Extract_archive_to_folder":["Succeeded"]}},"Apply_to_each":{"type":"Foreach","foreach":"@outputs('List_files_in_folder_(PleaseChoosePathDynamically)')?['body/value']","actions":{"IsFolder":{"type":"If","expression":{"equals":["@items('Apply_to_each')?['IsFolder']",false]},"actions":{"Move_or_rename_a_file":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"MoveFile","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"id":"@items('Apply_to_each')?['Id']","destination":"@{outputs('RootFolderPathOneDrive(PleaseUpdatePath)')}/Renamed/@{formatdatetime(utcnow(), 'yyyy-MM-dd-hh-mm-ss')}-@{items('Apply_to_each')?['Name']}","overwrite":true},"authentication":"@parameters('$authentication')"},"runAfter":{}}},"runAfter":{}}},"runAfter":{"List_files_in_folder_(PleaseChoosePathDynamically)":["Succeeded"]}},"List_files_in_folder_(PleaseChoosePathDynamically)":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"ListFolderV2","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"id":"b!BOIVsACSM02nAvrKA5sQqce2eGDhytpJrD6Ky1g1xl_-qoaIOl6yRo2252_HSDPt.01SRF3RDR3SFSATUXT5RCJKR4VMGQFQFCN"},"authentication":"@parameters('$authentication')"},"runAfter":{"Delete_file":["Succeeded"]},"metadata":{"b!BOIVsACSM02nAvrKA5sQqce2eGDhytpJrD6Ky1g1xl_-qoaIOl6yRo2252_HSDPt.01SRF3RDR3SFSATUXT5RCJKR4VMGQFQFCN":"/ZIPs"}}},"runAfter":{"JustForDemoTheFolderIDForListFilesButItDoesntAcceptIt":["Succeeded"]}},"JustForDemoTheFolderIDForListFilesButItDoesntAcceptIt":{"type":"Compose","inputs":"@substring(triggerOutputs()?['headers/location'],indexof(triggerOutputs()?['headers/location'],'folderId='),minus(length(triggerOutputs()?['headers/location']),indexof(triggerOutputs()?['headers/location'],'&includeSubfolders')))","runAfter":{"RootFolderPathOneDrive(PleaseUpdatePath)":["Succeeded"]}}},"runAfter":{}}}

 

Give it a go and let me know.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here

 

DamoBird365
Super User
Super User

Hi @AndreRadtkeKIT 

 

Quite a fun one this.  I have a folder call ZIPs on my OneDrive and if I drop a zip into it, it will extract, delete and then rename the files in a new folder called ZIPs/Renamed.  I have included a Copy/Paste solution for you below.  You can copy and paste this into your Cloud Flow - all you need is the when file is created in One Drive trigger and update the Compose Action with the name of your Folder for Zips that needs monitored (first compose) and also List Files in Folder Path as it needs a folder ID.  Make sure you create a Renamed folder too.  

 

The solution looks like follows:

DamoBird365_0-1617824004141.png

 

 

Which will be horrible to look at as it is a large solution, but copy this to your clipboard, click on add action and "My Clipboard" and paste and select the solution to import.

 

{"id":"5cd58a61-043a-49fa-b09a-69a3-65696bea","brandColor":"#8C3900","connectionReferences":{"shared_onedriveforbusiness":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness/connections/shared-onedriveforbu-5a107753-9d6f-4fbf-957e-72c6-987acc35"}}},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"SolutionByDamoBird365-UnzipAndRenameFilesWhenZipCreatedInOneDrive","operationDefinition":{"type":"Scope","actions":{"RootFolderPathOneDrive(PleaseUpdatePath)":{"type":"Compose","inputs":"/ZIPs","runAfter":{}},"Condition":{"type":"If","expression":{"contains":["@triggerOutputs()?['headers/x-ms-file-name']",".zip"]},"actions":{"Extract_archive_to_folder":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"ExtractFolderV2","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"source":"@{outputs('RootFolderPathOneDrive(PleaseUpdatePath)')}/@{triggerOutputs()?['headers/x-ms-file-name']}","destination":"@outputs('RootFolderPathOneDrive(PleaseUpdatePath)')","overwrite":true},"authentication":"@parameters('$authentication')"},"runAfter":{}},"Delete_file":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"DeleteFile","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"id":"@triggerOutputs()?['headers/x-ms-file-id']"},"authentication":"@parameters('$authentication')"},"runAfter":{"Extract_archive_to_folder":["Succeeded"]}},"Apply_to_each":{"type":"Foreach","foreach":"@outputs('List_files_in_folder_(PleaseChoosePathDynamically)')?['body/value']","actions":{"IsFolder":{"type":"If","expression":{"equals":["@items('Apply_to_each')?['IsFolder']",false]},"actions":{"Move_or_rename_a_file":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"MoveFile","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"id":"@items('Apply_to_each')?['Id']","destination":"@{outputs('RootFolderPathOneDrive(PleaseUpdatePath)')}/Renamed/@{formatdatetime(utcnow(), 'yyyy-MM-dd-hh-mm-ss')}-@{items('Apply_to_each')?['Name']}","overwrite":true},"authentication":"@parameters('$authentication')"},"runAfter":{}}},"runAfter":{}}},"runAfter":{"List_files_in_folder_(PleaseChoosePathDynamically)":["Succeeded"]}},"List_files_in_folder_(PleaseChoosePathDynamically)":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"ListFolderV2","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"id":"b!BOIVsACSM02nAvrKA5sQqce2eGDhytpJrD6Ky1g1xl_-qoaIOl6yRo2252_HSDPt.01SRF3RDR3SFSATUXT5RCJKR4VMGQFQFCN"},"authentication":"@parameters('$authentication')"},"runAfter":{"Delete_file":["Succeeded"]},"metadata":{"b!BOIVsACSM02nAvrKA5sQqce2eGDhytpJrD6Ky1g1xl_-qoaIOl6yRo2252_HSDPt.01SRF3RDR3SFSATUXT5RCJKR4VMGQFQFCN":"/ZIPs"}}},"runAfter":{"JustForDemoTheFolderIDForListFilesButItDoesntAcceptIt":["Succeeded"]}},"JustForDemoTheFolderIDForListFilesButItDoesntAcceptIt":{"type":"Compose","inputs":"@substring(triggerOutputs()?['headers/location'],ADD(indexof(triggerOutputs()?['headers/location'],'folderId='),9),sub(length(triggerOutputs()?['headers/location']),indexof(triggerOutputs()?['headers/location'],'&includeSubfolders')))","runAfter":{"RootFolderPathOneDrive(PleaseUpdatePath)":["Succeeded"]}}},"runAfter":{}}}

 

Give it a go and let me know.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here

DamoBird365
Super User
Super User

Hi @AndreRadtkeKIT 

 

Please use my 2nd post, the first includes a wee typo in the expression for the 2nd compose and you will get an error and even though I am trying to edit it, this forum interface won't let me.  Hope it works OK for you.

 

Damien

AndreRadtkeKIT
New Member

Hello @Anonymous 

 

thank you so much for these detailed information and I am very sorry to reply so late. Right now I am testing your solution but I am failing by copy pasting your code. My PowerApp does not provide to add your code because he does not recognize that I have your code in my clipboard. Do you know what I can do to import this code?

 

Thanks in advance.

Andre

AndreRadtkeKIT
New Member

Hey @DamoBird365  I figured out how to copy&paste the code. Your Flow is working if I test it in the developer / edit View, so far so great and many thanks :).

 

Now I am wondering what I have to do to get this flow working productive in my environment. I just saved the workflow and now I uploaded 2 zipfiles at once by drag n´drop to the corresponding folder in my onedrive. Nothing happens now. Am I doing sth wrong?

 

Greetings Andre 😉

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022- Season 2 has kicked off!

Users online (3,713)