How to extract .gz

Hi,
I’m currently working on a project where I need to handle .gz files. These files act like zip archives and contain multiple files within them.

The requirement is:

  1. Extract the contents of the .gz file into a folder.
  2. Then compress that extracted folder into a new .zip file.

I tried using the Unzip activity, but it doesn’t seem to work with .gz files.

Any suggestions on how to implement this would be greatly appreciated.

Thanks in advance!

Hi @jai_kumar2

You can use below code in invoke code activity to do the same

Alternatively, you can also consider using third party activity. From your studio, go to manage packages-> marketplace-> type the name of this activity and install to use.

Hi @sonaliaggarwal47 , thank you for your response. I’m currently encountering the following exception.

25.0.167-cloud.20202+Branch.release-s167.Sha.f996321a94f0fb43e96fe320d576f13b3e7ea623.f996321a94f0fb43e96fe320d576f13b3e7ea623

Source: Invoke Code

Message: Exception has been thrown by the target of an invocation.

Exception Type: System.Reflection.TargetInvocationException

in Main.xaml
at InvokeCode “Invoke Code”
at Sequence “Main Sequence”
at Main “Main”

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> ICSharpCode.SharpZipLib.Tar.TarException: Header checksum is invalid at ICSharpCode.SharpZipLib.Tar.TarInputStream.GetNextEntry() in //src/ICSharpCode.SharpZipLib/Tar/TarInputStream.cs:line 483
at ICSharpCode.SharpZipLib.Tar.TarArchive.ExtractContents(String destinationDirectory, Boolean allowParentTraversal) in /
/src/ICSharpCode.SharpZipLib/Tar/TarArchive.cs:line 620
at ICSharpCode.SharpZipLib.Tar.TarArchive.ExtractContents(String destinationDirectory) in /_/src/ICSharpCode.SharpZipLib/Tar/TarArchive.cs:line 600
at UiPathCodeRunner_9bb9c7df818b426b8106b6d7a903dc67.Run(String tgzFile, String outFolder)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span1 copyOfArgs, BindingFlags invokeAttr) --- End of inner exception stack trace --- at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span1 copyOfArgs, BindingFlags invokeAttr)
at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object providedArgs, ParameterModifier modifiers, CultureInfo culture, String namedParams)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object args)
at UiPath.Activities.System.Utilities.InvokeCode.CompilerRunner.Run(Object args)
at UiPath.Activities.System.Utilities.InvokeCode.NetCodeInvoker.Run(String userCode, List1 inArgs, IEnumerable1 imps, Object args)
at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Hi @jai_kumar2

Is your zipped folder only .gz or .tar.gz?

I believe code is for the latter option.

If it’s only gz, I think you will need to modify the code a little for same.

Else I would suggest the marketplace package and use activities available in it to unzip your .gz folder

Hi, yes it’s only gz and I tried change code but still not resolved.

@jai_kumar2

Did you try using the package?

But I cant use third party package.