Can I get the files inside a .zip without unzipping it?

Hello colleagues, good afternoon!
I hope you’re all okay.

I have a question regarding .zip files…
Can I get a list of all files that are inside a .zip file without needing to unzip it?

My situation is a list of approximately 10 zip files, where inside each one there are 100 files.
I need to find out which of these 10 zip files is a specific file that I will identify by its default name.

How do you think is the best way to handle this?

Will I need to unzip all the zip files to find the file I want and then delete the ones that won’t be useful?

Can I do a “for each” for these zip files, looking for my specific file?

Note: Concerning custom library packages, I would like you to avoid them, as my organization (company) is not very fond of using materials that are not official UiPath…

I need your help!

Hi @guintherlanger

I believe we need to unzip it to read the file path of each files in it
because if we try to get the filepath of all files inside zipped folder, it will throw error

so we need to unzip it and it can be done with EXTRACT/Unzip Files activity
https://docs.uipath.com/activities/docs/extract-files

and to get the list of files and its filepath we can use the below expression assigning it to a ARRAY Variable

arr_var = Directory.GetFiles(“Your folderpath”)

then iterate with FOR EACH activity to get the file path you need with IF conditions to filter in specific

Cheers

Hi @guintherlanger ,

Try below code
test.xaml (7.9 KB)

Please follow below steps before using this code.

1 - Install below package

2 - in_ZipPath - Pass File path where your zip file present
3 - in_ExtractFilePath - Pass File Path where you want specific file to be extracted.

Let me know if you find any difficulty.

This for one zip file once this will work we will put this in loop.

Thanks.

Hi @guintherlanger ,

Is it worked or you have used some other method ?

Hi @guintherlanger

In order to get the list of file names inside a zip file you can use a python library “zipfile”. As python integration is possible in UiPath using Python Scope you can try this method.

from zipfile import ZipFile

with ZipFile('file.zip', 'r') as zip:
    for info in zip.infolist():
        print(info.filename)

The code above gives the list of file names inside the “file.zip” zip file.

For detailed info refer this article

2 Likes

Hello @Palaniyappan, good morning!
Sorry for the delay to reply.

I don’t know if it’s my version of UiPath or something like that, but I haven’t found this activity you mentioned…
Was it some special package or something?

Hello @ermanoj3101, good morning!
Sorry for the delay to reply.

I believe this was the closest alternative, but the following error is occurring:

Actually, I didn’t understand the code very well because I’m a beginner, if you can help me with what I’m doing wrong, I appreciate it!

These here are the changes I made:

Hello @kumar.varun2, good morning!
Sorry for the delay to reply.

I liked your alternative, very simple and practical… But when I saw the activity I was a little lost… In which Input do I put the code?
Would you help me?

image

Hi @guintherlanger ,

Please install below package, it will work.

But still i will suggest to use @kumar.varun2 method, python is quick to implement.
If nothing works for you you can use c# code.

Thanks.

Hey @ermanoj3101, thanks for the reply!

But I have the package installed, what’s causing a problem is the parameters that I inserted in the activity/code. Because of that, it’s generating that error up there

Can you identify what I put wrong in the activity and in the code?

Hi @guintherlanger

Please check the attachment
Get File Names inside Zip.zip (2.5 KB)

It’s working code.

Can you show be what path you are passing in variables ?

Is error occurring on runtime?

I believe you can treat .zip folder as normal folders for getting files in Windows 10 but not if your OS is Windows Server

Hi
You can find this in Manage Packages → All packages tab

@guintherlanger

Hello everyone!
I thank each one individually who was willing to help me with the situation. Of all the possibilities, the one I got successfully was @kumar.varun2! =D

Because I’m using UiPath in my company, the versions used are a bit old, so there are some packages we don’t usually use, as well as some newer activities.

Regarding the @kumar.varun2 solution, I just changed the wrong parameters, after I stopped and thought a little, I managed to use it and it works perfectly.

Thank you very much once again, success everyone!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.