How can I filter and get only .zip files from a folder in UiPath?

I’m working on an automation where I need to process only the .zip files from a specific folder. The folder contains many different file formats such as .jpeg, .mp4, .pdf, .xlsx, .zip, and others.

I want UiPath to look into this folder and return only the files with the .zip extension so that I can loop through them and perform further actions (like extraction or validation).

Could anyone suggest the best approach to filter only .zip files?

  • Should I use a Directory.GetFiles method with a filter?
  • Or is it better to use a LINQ expression?
  • Any example workflows or expressions would be really helpful.

Thanks in advance!

1 Like

Hi @ANJUVISH

Directory.GetFiles(“C:\YourFolderPath”, “*.zip”)

Use the above, it will give you .zip files.

5 Likes

Hi @ANJUVISH

You can just use Directory.GetFiles(folderPath, “*.zip”) and it already returns only the .zip files. No need for a complex LINQ unless you really want to.
Then you loop over that array and do your extraction or whatever action you need. Super simple and works fast.

But if you really prefer LINQ, you can do something like:

Directory.GetFiles(folderPath).Where(Function f => f.EndsWith(“.zip”))

It just filters the full file list and keeps only the .zip ones. Works fine too, just a bit more typing compared to the direct filter.

If this helped you fix the problem, please mark as solution so it can help others too

1 Like

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