Searchin in array of strings for a string with patter

So I got an array of strings from a folder witch contains the full path of various files in a directory.

I want to retrieve as string the one that fills somthing like “ChosenFileName”.

To be more excpecific:

I’ve got a variable called FilesPath. This variable contains full path of various files. I need to store in a string variable the one that files a name.

Array of strings:

C:\UiPath\ISS_001_PSADataDownload\FirefoxDownloadTemp\PRT_RD_AC_DEUR_FDZ.20230821135148.tar.gz,
C:\UiPath\ISS_001_PSADataDownload\FirefoxDownloadTemp\EKD_RD_AC_DEUR_FDZ.20230821135148.tar.gz

So I want to finde the PRT file but dont know the full name of the file just the PRT.

Hi @Pelayo_Celaya_Fernandez ,

Assuming that the file name starts from PRT, we can check with the below Expression :

FilesPath.Where(Function(x)Path.GetFileName(x).StartsWith("PRT")).FirstOrDefault
1 Like

Hi

you can try something like this with ASSIGN activity

arr_variable = arr_variable.AsEnumerable.Where(Function(a) a.ToString.Contains(your variable name that holds the filename)).ToArray()

this will give the array as output which has the filename you are looking for

Cheers @Pelayo_Celaya_Fernandez

Hi @Pelayo_Celaya_Fernandez

Could you please try the following query for the same?

FilesPath.Where(Function(filePath) filePath.Contains("PRT")).FirstOrDefault

Hope this helps,
Best Regards.

Thanks this worked. Do you know any course to practice this kind of vbnet. I need to stop asking this questions :smiley:

1 Like

LINQ was used:
[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum

1 Like

@Pelayo_Celaya_Fernandez

You can find numerous resources in this place: https://www.youtube.com/results?search_query=vb.net+functions+for+uipath

It’s a good idea to get familiarized with the functionalities of individual functions & then start implementing them in the queries accordingly.

Hope this helps,
Best Regards.

1 Like

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