5

I'm unaware on how to make "~" expand using path. I would expect that using path functions, directory/file class would automatically handle it.

import "dart:io";
import 'package:path/path.dart';

void main() {
  print(absolute("~"));
  var d = new Directory("~");
  print(d.absolute.path);
}

Prints

/private/tmp/dummy/dummy/bin/~
/private/tmp/dummy/dummy/bin/~
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
adam-singer
  • 4,489
  • 4
  • 21
  • 25
  • 4
    `Tilde` in path can be expanded only by the POSIX shell. It cannot be handled automatically because Dart File System I/O based on internal OS implementation (kernel). It not based on an `OS specific shell`. You must not use them. The `globbing` does not expand `tilde` into `HOME` environment variable. You may only write by hand your own implementation or avoid using them. – mezoni Mar 10 '14 at 19:17

1 Answers1

4

Like @mezoni said in his comment, this is not supported everywhere. Some libraries have support built in, others have not.

A workaround:

import 'dart:io' as io;
import 'package:path/path.dart' as path;

...

if(io.Platform.isWindows) {
  print(path.absolute(io.Platform.environment['USERPROFILE'])); // not tested
} else {
  print(path.absolute(io.Platform.environment['HOME']));
}

see also Access to user environment variable

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567