How to extract matching foldername

Hi, bot is reading data from excel file and searching for that foldername in a location but unable to open it and proceed further because:
the excel sheet contains RF123
but the exact foldername is RF123-001 (after “-” it can be any number of digits)

so when i search, the bot has to extract the matching foldername and keep in a variable, how do i do that?

Hi @Geeta,

Here is possible solution.

Sample Code:
DirectrySample.xaml (10.1 KB)

Thanks,
Ashok :slight_smile:

1 Like

hi @ashokkarale
im using for each row in DT, where currentrow(“Part”) will be the foldername

currentrow(“PART”).Split(“")((currentrow.Split(”").Length)-1).StartsWith(currentrow(“PART”))

will work?

Share that Part column value please

The column values extracting are:
F50B1320280
F50B13203B2
FGFB1200158

But the actual folder names are like this: i want to extract full name of folders by searching matching pattern
F50B1320280-001
F50B13203B2-002A1
FGFB1200158-0034B2

or help me to find the matching folder and search for a specified filenames
Directory.GetFiles(folderpath + CurrentRow(“N°RFQ”).ToString+“"+CurrentRow(“PART”).ToString,”.“,searchOption.AllDirectories).Where(Function(s) s.EndsWith(”.stp")Or s.EndsWith(“.PDF”)).Count

Current(“part”) is F50B1320280 , but bot is unable to search becuase it contains “-012A00”

@Geeta,

I have updated the logic as per your requirements.

Input file:

Solution:

Sample Code:
DirectrySample.xaml (15.1 KB)

You can make the changes specific to your need now.

Thanks,
Ashok :slight_smile:

Hi @Geeta ,

This code will search for all directories within the specified directory path that start with the value from the “PART” column and return the first match found

Path.GetFileName(Directory.GetDirectories(“C:\Users\sneha.vijayan\Documents\UiPath\getfolder”, CurrentRow(“PART”).ToString & “*”, SearchOption.AllDirectories).FirstOrDefault())