Is it possible to extract just a specific file from a ZIP?

Hello Forum

I´m working on a automation and I need to download a ZIP and extract a file from it… The thing is that sometimes this ZIP brings a list o files I don´t need, so I would rather not to extract all the files from the ZIP but just the one I need. Is there any way that maybe I can extract just the file I need depending on some conditions regarding the name of the file? Maybe doing a loop inside the ZIP?, or do I have to extract all files to a folder and then extract the correct file from it?

And I have a bonus question… How do you normally get a file that it´s downloaded during execution? What expression do you use to get the file path or name of the Downloaded file?

Thank you very much. I know the questions are a bit simple, but I haven’t really worked with file manipulation yet.

Regards

1 Like

Hi,

You can use unzip command in a batch file and run that batch file form studio using start process activity.

Extracts the enitre folder at temp location to be discarded later and gives you the file it needs depending what you passed as inputs to this command.

Hope that helps
Thanks.

Thanks.

Hi @Luis_Fernando

We can’t get the specific file from the zip file without extraction. If you don’t want the files in zip folder, then extract the folder in temp location then copy the file you need to a separate folder then delete the temp folder.

Normally, we all have same path for downloaded files i.e., “Downloads”.
or
You can either enable the “Ask where to save each file before downloading” in chrome settings to change the name and location during automation wherever you want.

Regards,

@Luis_Fernando ,
For this You can Unzip the whole file in a folder and later you can extract a specific file using required logic .

To get the latest file from the downloads folder you can use the below method.

Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"\Downloads").[Select](Function(x) New FileInfo(x)).Where(Function(f) f.Extension.Equals(".pdf")).OrderByDescending(Function(x) x.LastWriteTime).Take(1).ToArray()(0).ToString

Note : I have assumed that the files are PDF please change it accordingly.

Regards,

Hello Friends @prateek.mehandiratta9 , @supriya117 and @Jithesh_R

Problem is solved
I asked Chat GPT for VB.Net expression that searched for the path of the files that met a condition. The result was this

Imports System.IO

Dim folderPath As String = “C:\YourFolderPath” ’ Specify the folder path where the files are located
Dim searchTerm As String = “Manifiesto” ’ Specify the search term

’ Get all files in the folder that match the condition
Dim files As String() = Directory.GetFiles(folderPath, “" & searchTerm & "”)

’ Extract the first file that matches the condition
If files.Length > 0 Then
Dim specificFile As String = files(0)
’ Perform further operations with the specific file
Console.WriteLine("Found file: " & specificFile)
Else
Console.WriteLine(“No file found matching the condition.”)
End If

So I modify what it had to be modified and everything now works perfectly.

The only thing that I´m still restless about is that the first solution I design was using the activity available in studio, "For each file in Folder ", and I was unable to make it work. For some reason it doesn´t seem to iterate through the files in the folder. Here are some screenshots
PD: The only thing I missed capturing was the output panel result, But I can assure you that the loog inside the for each wasn´t available when the process finished.
image
image

Let me know what the error is here, I don’t want to be the guy that doesn´t know how to make work this activity.

As always Thank you very much for the attention.

Regards

Luis Fernando Pazos, The First Venezuelan RPA Developer

2 Likes

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