toWindowsPath function

String toWindowsPath(
  1. String anyPath
)

To windows path, both / and \ are separators.

/a/b   => \a\b
\a/b   => \a\b
/C:/a  => C:\a
C:\    => C:\
/C:/   => C:

C: alone is the current directory of the drive, not its root. A drive path written with / is returned as is (C:/x => C:/x).

Implementation

String toWindowsPath(String anyPath) {
  var context = windows;
  var parts = contextPathSplit(context, anyPath);
  // Handle C:\xxx
  if (parts.length > 1 && parts[1].endsWith(':')) {
    parts = parts.sublist(1);
  }
  return context.joinAll(parts);
}