Search code examples
c#path-separator

Directory.GetFiles with '/' on any platform


I'm trying to get a path with '/' char using Directory.GetFiles or Directory.GetDirectories whitout replacing the string each time I produce one. I would simply ask the librairie to use '/' as the directory separator even if I have some Macro telling him to use AltSeperator on specific OS.


Solution

  • Unfortunately that doesn't seem to be possible.

    Path.DirectorySeparatorChar and Path.AltDirectorySeparatorChar depend on the OS your app is running on, and are read-only.

    According to the docs DirectorySeparatorChar is \ on Windows and / everywhere else, and Path.AltDirectorySeparatorChar is (currently) always /.