How do I find the current directory, in Dart?

2019-02-17 01:59发布

问题:

I want to know what the current directory is. I don't want to shell out to run pwd. Is there an easy way to do this in Dart?

回答1:

Indeed there is!

import 'dart:io';

main() {
  Directory current = Directory.current;
}

Note: this only works on the command-line, not in the browser.

Read more about the API docs for Directory.current.



标签: dart dart-io