Simple Regex or VB Expression to split

I need to get the name from the File inside the Folder

Folder Path : “C:\RPA\Dev\Test\Buyer Files”
This Folder has some files

Raj Buyer.csv
Rahul Buyer.csv
Pooja Buyer.csv

I need the Names like:
Raj
Rahul
Pooja.

I use For Each and ‘FileName’ in Directory.GetFiles(MyFolder)
I used Assign
BuyerName = split(FileName, " "c).First

but getting only : C:\RPA\Dev

Thanks.

Hey!

Try this:

  1. Take one assign inside the for each pass the expression like this
FileName = Path.GetFileNameWithoutExtension(Item)

This will give you the full Name

Now you can use like this to get the first name

FirstName.Split(" "C)(0)

This will give you the first Name

Reference:

Regards,
NaNi

Hi @Gagan_Chaudhari

You can try this approach

xaml for reference

GetBuyerName.xaml (6.3 KB)

Hi,

Another solution:

If there is possibility filename doesn’t contain whitespace, the following might be better. (This expression doesn’t throw exception even if there is no whitespace. It returns whole filename without extension)

System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileNameWithoutExtension(filename),"^\S+").Value

Regards,

filepath.replace(folderpath+“",”")

try this it will give you filename