How to read Only file name and not full path in Uipath dynamic dropdown button

Hello All,
I am displaying a form which has a dynamic dropdown menu. As you see in the picture, my drop down reads complete path. How to read only file name?

I have used assign function using System.IO.Directory.GetFiles (file path) as array of string. I am not able to see any option to read array of string without extension. I tried path.GetFileNameWithoutExtension(AssignedPath) but this also gives me error and doesnt work.

Is there any way to just display file name?

Hi,

You need to try this code;

DirectoryInfo di = new DirectoryInfo(YOUR_DIRECTORY)
di.GetFiles().Select(Function(x) x.Name).ToList() → this will return you list of only file names

Path.GetFileName(variableContainingFullPath)

what is x here? or should i replace it with path name?

This is not working as i have array of string due to dynamic dropdown. This works good when i have single string

Are you trying to get the filename of all the options in the pulldown, or just the one that is currently selected?

yes to all the option as i just want to display the filename and not full path

No you don’t need to change it. x indicates a key for LINQ command to iterate every file in the list. You can use any name in Function, it doesn’t matter.

You will just change the YOUR_DIRECTORY.

Then you’d use Find Children to get an array of all the options in the pulldown, then For Each through the array and use the Path.GetFileName on each item to get just the filename.

Can you please check what I am doing wrong?

The issue here is I can use for loop in form.

You can’t use UiPath to change the options that are in the web form. Whoever created that web form has to change it in their code.

Its not a web form. Its UiPath form package that i am using for desktop folder files reading

Oh then you need to change the value in the data that you’re passing to the form for the pulldown, before you open the form. For Each through the array you’ve got the full paths in, and add just the filename for each item into a list variable using Path.GetFileName

how can i do that? do you have example?

An easier way would be to just use Erkan’s expression to assign to your array variable:

DirectoryInfo di = new DirectoryInfo(YOUR_DIRECTORY)
di.GetFiles().Select(Function(x) x.Name).ToList()

Hi @tarangmehta1195

Assign:
FileName = System.IO.Path.GetFileNameWithoutExtension(yourFilePath)

In yourFilePath pass the your file path variable

not working. What variable type is di?

@supriya117 This works good if there is single file. I have multiple file in my folder. So my variable type become System.String and thats creating issue.

That’s not returning an array. That’s the expression you’d use if you were looping through your original array, and it returns string. This expression you assign to your existing array instead of your Directory.GetFiles:

new DirectoryInfo(YOUR_DIRECTORY).GetFiles().Select(Function(x) x.Name).ToList()