W3cubDocs

/Dart 2

resolveSymbolicLinks method

Future<String> resolveSymbolicLinks ()

Resolves the path of a file system object relative to the current working directory.

Resolves all symbolic links on the path and resolves all .. and . path segments.

resolveSymbolicLinks uses the operating system's native file system API to resolve the path, using the realpath function on linux and OS X, and the GetFinalPathNameByHandle function on Windows. If the path does not point to an existing file system object, resolveSymbolicLinks throws a FileSystemException.

On Windows the .. segments are resolved before resolving the symbolic link, and on other platforms the symbolic links are resolved to their target before applying a .. that follows.

To ensure the same behavior on all platforms resolve .. segments before calling resolveSymbolicLinks. One way of doing this is with the Uri class:

var path = Uri.parse('.').resolveUri(new Uri.file(input)).toFilePath();
if (path == '') path = '.';
new File(path).resolveSymbolicLinks().then((resolved) {
  print(resolved);
});

since Uri.resolve removes .. segments. This will result in the Windows behavior.

Implementation

Future<String> resolveSymbolicLinks() {
  return _File._dispatchWithNamespace(
      _IOService.fileResolveSymbolicLinks, [null, _rawPath]).then((response) {
    if (_isErrorResponse(response)) {
      throw _exceptionFromResponse(
          response, "Cannot resolve symbolic links", path);
    }
    return response;
  });
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-io/FileSystemEntity/resolveSymbolicLinks.html