How get path as string without leading "slash" in Windows in Dart SDK? How get path as string without leading "slash" in Windows in Dart SDK? dart dart

How get path as string without leading "slash" in Windows in Dart SDK?


This code works on all platforms.

import 'dart:io';void main() {  var path = Platform.script.toFilePath();  print(path);  var uri = new Uri.file(path);  print(uri.toFilePath());}

P.S.

Similar exception (Illegal character in path) can occurs inside Dart SDK (in some cases) when used scheme ""dart-ext":

Unhandled exception:Unsupported operation: Illegal character in path}#0      Uri._checkWindowsPathReservedCharacters.<anonymous closure> (dart:core/uri.dart:395)#1      ListIterable.forEach (dart:_collection-dev/iterable.dart:39)#2      Uri._checkWindowsPathReservedCharacters (dart:core/uri.dart:390)#3      Uri._toWindowsFilePath (dart:core/uri.dart:1018)#4      Uri.toFilePath (dart:core/uri.dart:992)#5      _filePathFromUri (dart:builtin:249)'package:dart_and_cpp_classes/src/cpp_extension.dart': error: line 3 pos 1: library handler failedimport "dart-ext:cpp_extension";^'package:dart_and_cpp_classes/cpp_extension.dart': error: line 3 pos 1: library handler failedimport 'package:dart_and_cpp_classes/src/cpp_extension.dart';^'file:///C:/Users/user/dart/dart_and_cpp_classes/bin/use_cpp_extension.dart': error: line 1 pos 1: library handler failedimport 'package:dart_and_cpp_classes/cpp_extension.dart';^


Take a look at the path package import package:path/path.dart.
I don't have Windows running here so I can't verify anything.

After a brief look I found:

/// An enum type describing a "flavor" of path.abstract class Style {  /// POSIX-style paths use "/" (forward slash) as separators. Absolute paths  /// start with "/". Used by UNIX, Linux, Mac OS X, and others.  static final posix = new PosixStyle();  /// Windows paths use "\" (backslash) as separators. Absolute paths start with  /// a drive letter followed by a colon (example, "C:") or two backslashes  /// ("\\") for UNC paths.  // TODO(rnystrom): The UNC root prefix should include the drive name too, not  // just the "\\".  static final windows = new WindowsStyle();  /// URLs aren't filesystem paths, but they're supported to make it easier to  /// manipulate URL paths in the browser.  ///  /// URLs use "/" (forward slash) as separators. Absolute paths either start  /// with a protocol and optional hostname (e.g. `http://dartlang.org`,  /// `file://`) or with "/".  static final url = new UrlStyle();