dart-lang/path

Provide clearer documenation on use age of / as root

Opened this issue · 3 comments

The documentation doesn't provide clear guidance on how you stipulate a root path in a cross platform manner.
Whist \tmp isn't an absolute path on windows it does describe a path that is relative to the root directory of the current drive and below I will refer to this as an root relative path.

Reading the documentation its not clear how to stipulate a root relative path.

For instance are each of the following the same:

join('/tmp');
join('/', 'tmp');
join('\tmp');
join('', 'tmp');

It would be useful if the documentation was explicit on this point.

I want to solve this issue. Can someone guide me through the process?

lrhn commented

I can't answer how to do it, which suggests that it is either a documentation issue or a missing feature.

(It's likely that it is a missing feature, since Windows doesn't have canonical root. You might conside \foo a root path in Windows, but Windows doesn't. And the path package likely also doesn't. So there is no concrete feature that can be consistently provided.)

My questions was really around how you specify '/' in a cross platform manner.

The path package does have the platform specific 'separator' method so you could write:
join(separator, 'tmp');

DCli has the 'rootPath' getter which I use to partially solve this problem. It is relative to the current drive on windows.

https://onepub.dev/documentation?package=dcli_core&version=2.1.0&className=rootPath.html