cake icon indicating copy to clipboard operation
cake copied to clipboard

Use OS-native directory separators in Path.FullPath

Open jnm2 opened this issue 5 years ago • 4 comments

There are applications which do not understand the alternate directory separator; for example, https://github.com/cake-build/cake/issues/2337. There have also been multiple CLI tools I've used where I had to do .FullName.Replace('/', '\\').

Would you consider returning OS-native directory separators from Path.FullName? It will just work in all situations, and it will not stand out and look strange on Windows any longer even when it does work. (At times, I've manually edited MSBuild logs etc so people don't ask why I'm using weird paths.)

jnm2 avatar Nov 25 '18 23:11 jnm2

@jnm2 I would be OK with using System.IO.Path.DirectorySeparatorChar as the separator (see https://github.com/cake-build/cake/blob/develop/src/Cake.Core/IO/Path.cs#L41), but I wonder how much work it would be and if this would bring any side effects with it. We would also need to fix tests.

Perhaps we could add an overload to FilePath and DirectoryPath to specify (non-UNC) path separators as well, for cases where you would want to use a non OS-native path separator?

public FilePath(string path, char separator) : base(path, separator) {
   ...
}

Just thinking out loud here.

patriksvensson avatar Nov 26 '18 05:11 patriksvensson

Sweet! If I get to this before anyone else, I'll submit a PR that keeps the APIs the same and chooses System.IO.Path.DirectorySeparatorChar. While fixing the tests, we can see what comes up?

jnm2 avatar Nov 26 '18 21:11 jnm2

I have also had challenges passing paths to other tools on Windows, that does not like the '/' separator. My thought was to add a method to FilePath and DirectoryPath with the "right" separators e.g. FullOsPath to not mess with expected outcome of FullPath?

Roadrunner67 avatar Aug 20 '19 06:08 Roadrunner67

I encountered an issue with NuSpecContent that requires OS-native directory-separator ('') when globbing. c:\foo**\bar.dll works, c:/foo/**/bar.dll does not

runehalfdan avatar Aug 11 '20 12:08 runehalfdan