Assigning special characters (&) to my directory variable

I use the function of: Directory.GetDirectories(Path.ToString) to get the directory of my files, however, if the directory contains a " & " it does not record this, thus leading to my script breaking.

Is there a way to assign the directory to an string where special characters are included?

// Best regards
RPA newbie

It is working for me even the directory name contains $ @pnkovsted

Can you let me know your file name so that I will try the same


Correction: I use Get Text inside the the folder to get the text from the bar in the top. When it copies this, it cannot include the special character of " & ".

You can get it in the loop itself right @pnkovsted?

Why don’t you capture that and use instead of get text activity

I’m not sure what you mean. Could you please provide an example?

Thank you for your help!

As in the above screenshot, you will get the entire path directly instead of clicking and copying in the bar on the top @pnkovsted. Please try that

Here instead of message box, assign it to a variable so that you can use it further instead of copying


My problem is here:

I’m standing here, and need the whole path of the files. If I should loop over the directory I would need
to have the directory, and it is dynamic and changes every time. This time it is 1072 Eva & Morten Elsig, next time it could be whole other.

I have a variable based on the initial 4 numbers, but the rest of the name is found automatically.

I have tried:


But to no success.

@HareeshMR do you know any other way?

Is there a way to find which folder you want to open or any specific hint that you want to open @pnkovsted?

Yes I have an excel file with all the numbers.



did you tried

Directory.EnumerateDirectories(yourpathstring,"*",SearchOption.AllDirectories) it will returns all sub directory name inside floder


it will returns all files inside subfloders as well

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