Regex - getting filename out from filepath

Hi friends

Any one who can help me out with a small regex?

I need to identify filename fom filepath

Example of filepath:
DIRABC\FolderNameABC\BillSegmentIDIdentifier.xlsx

I want output : BillSegmentIDIdentifier.xlsx

Path can vary - but file will always be .xlsx :))

Hi @JDK

So the idea is to start ur regex code from the end of ur string.

here’s the code : ([^\\]*$)

Cheers @JDK

1 Like

Hi,

Can you try the following expression?

System.IO.Path.GetFileName(strData)

or

System.Text.RegularExpressions.Regex.Match(strData,"[^\\]+?xlsx$").Value

Regards,

1 Like

Hi @JDK,

there’s one simple method to get filename from path,
Path.GetFilename(“full path”)

2 Likes

Thanks buddy
Worked like a charm :slight_smile:

Thank you - this worked very well aswell :slight_smile:

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