Zip and unzip a file in uipath

Hi all,

I am working on a project where I have to unzip a file and do operation and zip it back. I am doing this using powershell code.
-> this code unzips a file
Expand-Archive -LiteralPath sourceFilePath -DestinationPath destinationFilePath

The problem I am facing is the powershell script does not accept wildcards.
Is there any other way to do this???

Regards
Devbrath

Hello @devbrath
To use the wildcard you could use vb.net within UiPath possibly, then pass the filename to the script.
I believe System.IO.Directory.GetFiles() allows a searchpattern

You can also check out the Zip/Unzip Custom activity:

There is also an Invoke Method solution here:

Regards.

1 Like

Hi @devbrath and @ClaytonM ,
Can you check . If is this solve your problem.

Regards
Balamruugan

5 Likes

@balupad14
I have installed the BalaReva external activities.
My process requires me to unzip files, and some zip files have nested zips.
I have a while loop that looks to see if there are any more zips within a folder, and if so unzips.
I am getting the following error:
{
“message”: “An error has occured while unzipping the packages, error message: System.NotSupportedException: Unknown header: 892548665\r\n at BalaReva.Externals.UnZipFile.Execute(CodeActivityContext context)\r\n at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)\r\n at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)\r\n at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) at BalaReva.Externals.UnZipFile.Execute(CodeActivityContext context)\r\n at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)\r\n at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)\r\n at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)”,
}

Here is a screenshot of my workflow:


any ideas on how to fix this?

1 Like

Hi @KaylaC,

Can you please attach the Zip to inspect it. If you feel it is confidential . you can sent it my message.

Regards
Balamurugan.S

Hi! :slight_smile:
i don’t know the name of the file that i want to unzip… How do i say, on the unzip activitie, something like *.zip?

1 Like

In a for each activity

You will need the filepath with the name of the file, so you will need to get the files in a folder with a pattern.

You can use this:
System.IO.Directory.GetFiles(folderPath, "*.zip")
Or change “*.zip” to meet your needs as a pattern. This will give you all the files in the folder, so you will need to unzip all files using a For Each loop as was suggested.

For example,

For each file In System.IO.Directory.GetFiles(folderPath, "*.zip")
    Unzip // use file for SourceFilePath

Regards.

3 Likes

i dont have unzip activity

1 Like

Hi @yusufs.adi,

Follow these step that leads you to get the unzip activity.

Regards
Balamurugan.S

1 Like

hay @balupad14
thanks

1 Like

@balupad14

i am trying to install this package i am getting error …> Package Installation Failure.

Regards,
Heena

1 Like

Can you share me the screen shot please. Because it is working for me.