Uipath.Core.Activities.SelectFile - Extract file path

I’m asking the user to select the file using Uipath.Core.Activities.SelectFile when I then save the output file I want to save it to the location they selected the input automatically.

For example if the source is c:\files\InputFile.xls
I want to output to “c:\files\Inputfile”+ “-Output” +".xls"

I have worked out how to extract the file name but but its the path I want so how would I extract everything to the left of the last “”?

Use Path.GetDirectoryName()

result = Path.GetDirectoryName("C:\MyDir\MySubDir\myfile.ext")

The result will be “C:\MyDir\MySubDir”

2 Likes

Hi ,

You can use Path.GetDirectoryName.

Thanks I realised my mistake I was testing to a message box and it was blank because I was using

Path.GetDirectoryName("VARIABLE").ToString

Did not need the " ", works fine with

Path.GetDirectoryName(VARIABLE).ToString

Thank you both for confirming I was on the right path just wrong syntax!

1 Like

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