Getting the file name from a file path

Hello all,

So I have a process where I can assign the file path of a random file in the folder to a variable.

What I need to do with that is get only the name of the file. as below:
input : ‪C:\Users\user\Documents\UiPath\BK\ attachments\289cfc07d7a9e9.pdf
output : 289cfc07d7a9e9

so i need to remove the file type as well as the other parts before the name.

Any idea how I can do this and assign it to a variable?

1 Like

Hi,

Hope the following expression helps you.

filename = System.IO.Path.GetFileNameWithoutExtension(strData)

Regards,

where can i put the variable that has the filepath?

Hi,

where can i put the variable that has the filepath?

strData is variable for filepath.

strData="C:\Users\user\Documents\UiPath\BK\ attachments\289cfc07d7a9e9.pdf"
filename = System.IO.Path.GetFileNameWithoutExtension(strData)

Regards,

1 Like

worked perfectly!

1 Like

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