Read file name some text?

How to read file name (only number yellow highlight)
I want number after text Charge_ and before _ as below.


I want output round 1 = 473 , round 2 = 594 , round 3 = 649

Please guide me about it.

Hi @fairymemay

Hope this helps:



@vinithareddyk123 What activity for use in uipath?

Hi @fairymemay,

You can use a for loop to get the file name first
For File in Directory.GetFiles(YOURPath,"*.pdf")

Use the File.ToString as input to Matches activity and use the regex expression to extract the number : Charge_(?P<ItemNumber>\d+)_

Your variables will then be accessible in


Hi @fairymemay

You can write inside assign activity also.

Use for each to loop through the files in folder using Directory.getFiles(“YourFolderPath”,"*pdf")
and later passed the item value to the regex expression as shown below.




Hope these steps would help you resolve this

—use a assign activity like this
Arr_filepath = Directory.GetFiles(“your folder path”,”*.pdf”)

Where arr_filepath is a array fo string variable

—now use a FOR EACH loop and pass the above variable as input and change the type argument as string

—inside the loop use a writeline activity like this


This will give the value you want in output panel

Here we are trying to split the text from first underscore and again splitting that with first underscore

First we will get this
Next will get this

Both is done in a single expression

Cheers @fairymemay

1 Like

@fairymemay - please check this post…

Here instead of change it to (1) …

StrArrayNum =  Directory.GetFiles("YourFolderName","*.pdf").select(Function(x) path.GetFileNameWithoutExtension(x).split("_"c)(1)).toarray

Here StrArrayNum is of variable type String Array

1 Like

Another option would be to Split on _ and get element 1.

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