Wednesday, January 16, 2013

Breaking Change in dart:io Path() Class Makes it Easier to Deal with Windows Paths

Some changes are coming to the Path class constructor that will help make Windows paths platform agnostic. William Hesse gives us the details

I have finally changed the new Path(String path) constructor to automatically convert Windows paths into platform-independent paths, the way that new Path.fromNative(String path) does now.  I found no cases where code needed to create a path without doing this conversion on the Windows platform, so we thought we should make it the default.  It is fine if this conversion is done more than once to a path, since it has no effect the second time.

The reverse of this conversion is done by the toNativePath() method of Path, which returns a string which follows the conventions of the platform.  On Windows, slashes are changed back to backslashes, an initial slash is removed from a drive letter, if present, and a network share starting with two backslashes has them restored.

The previous functionality of new Path() has been renamed to new Path.raw(String path), but we are considering removing it, since it seems to be more confusing than useful.  If anyone knows of a use case for it, please chime in.

.  Note that these are the bleeding_edge API docs, and not the slightly more stable Latest API docs at

As always, we invite you to join our Dart mailing list, ask questions on Stack Overflow, or file feature requests on