resolveSymLink function

String resolveSymLink(
  1. String pathToLink
)

Resolves a symbolic link to its target path.

This function follows symbolic links to their ultimate destination, whether they point to files or directories.

pathToLink - The path to the symbolic link to resolve

Returns the absolute path to the target of the symbolic link.

Example:

final target = resolveSymLink('/path/to/symlink');
print('Symlink points to: $target');

Implementation

String resolveSymLink(String pathToLink) {
  final normalised = canonicalize(pathToLink);

  String resolved;
  if (isDirectory(normalised)) {
    resolved = Directory(normalised).resolveSymbolicLinksSync();
  } else {
    resolved = canonicalize(File(normalised).resolveSymbolicLinksSync());
  }

  return resolved;
}