Illegal Characters in path

I’m using a get files activity to get all the .png images out a folder for further processing, but for some reasson I get an error that there are illegial charachters in the path.
I’m using a jsonfile to get the path, but I tried hardcoding it and the result is the same, the path is fully correct, I can physicly navigate to it.
The path I’m using is “c:\abb\pdf” (in my json the slashes are escaped), the filter I’m using is “(.png|.PNG”), anyone an idea what is causing the error? In other post I read you should trim the variable, which I tried, but no dice…

Hi @Daniel_D,

Inside json file, give this path “c:\\abb\\pdf”

Try this.


It is, as you can read in my previous post the slashes are escaped in my .json
I’m also using the same variable to create the directory and there it’s not giving me an issue


These character may be available in your path string,


They are’nt, I’ve used a messagebox to ouput the path, and UiPath reads it as C:\abb\pdf, as it should…


Try to check this condition using a IF activity before assign/save the file path.

(Not String.IsNullOrEmpty(path) AndAlso path.IndexOfAny(System.IO.Path.GetInvalidPathChars()) >= 0) 

Hi @Daniel_D,

I had that issue a few days ago, this means that you have chars that are not valid in windows. Please add a write line so you can visualize it better if you’re not sure which character might be just copy-paste it and we will help you :slight_smile:

I’ll try that thanks

Look at the screenshot, that’s the output of the variable, in my .jsonfile it come to: “C:\abb\pdf”

I have a feeling that either the files themselves have an illegal character, or the “|” in filter does not work.
How are you using your filter exactly?

For example inn directory.getFiles you can only set one search parameter, and the “OR” will not work. You can try some solutions in this thread:

What worked for me, was using this in an assign activity:

files = Directory.GetFiles(pathdir, "*.*",0).Where(Function(X) X.StartsWith("ABC") Or X.StartsWith("DEF")).ToArray()

Where files is an array of strings. You could try applying this to your use case by changing the path and instead of StartsWith, use EndsWith(".png").

1 Like

I used the same filter before. I use the getfiles activity and it worked before, the only things that have changed are the folders and instead of hardcodding the path I use a configfile

It return -1, meaning it couldn’t find any invalid characterss right?

You’re right it’s the filter that’s not working, I removed it and then it works, I still need it but at least know I know what the prob is

most likely it was the pipe, I extract the images out of a pdf myself, so I’m sure the extension will be .png and don’t really need the second option so I changed my filter to “*.png” and that solved the problem

1 Like

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