Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open folder which contains comma in its path

Tags:

c#

.net

I need to open folder through windows explorer using C#. It is working fine untill there is comma in folder path. Here is an example:

System.Diagnostics.Process.Start("explorer.exe", "C:\\folder\\another-folder\\123,456");

The error is: The path '456' does not exist or it is not a directory.

Any solution please :)

like image 229
sturmgewehr Avatar asked Sep 20 '10 08:09

sturmgewehr


People also ask

Can a file path have a comma?

Yes. Commas and dots are fine.

Can you use comma in a folder name?

Punctuation, symbols, or special characters (periods, commas, parentheses, ampersands, asterisks, etc.) should be avoided.

What is the path to a folder?

A path is a slash-separated list of directory names followed by either a directory name or a file name. A directory is the same as a folder.


1 Answers

Try adding double quotes around your path:

System.Diagnostics.Process.Start("explorer.exe", "\"C:\\folder\\another-folder\\123,456\"");

Side-note: you might find it easier to write paths using a verbatim string literal, to avoid having to escape the slashes:

System.Diagnostics.Process.Start("explorer.exe", @"""C:\folder\another-folder\123,456""");
like image 142
Hosam Aly Avatar answered Oct 17 '22 21:10

Hosam Aly