tildeExpansion method

String tildeExpansion(
  1. String path
)

Implementation

String tildeExpansion(String path) {
  if (path.startsWith('~')) {
    String separator = Platform.pathSeparator;
    List<String> parts = path.split(separator);
    if (parts[0] == '~')
      parts[0] = ((Platform.environment.containsKey('HOME'))
          ? Platform.environment['HOME']
          : "")!;
    else {
      String user = parts[0].replaceAll('~', '');
      try {
        parts[0] = getpwnam(user).homePathTo;
      } catch (e) {
        //print("failed to find user $user");
      }
    }
    path = parts.join(separator);
  }
  return path;
}