How do I get the script path in Dart?

2019-06-20 08:18发布

问题:

I need to find out the directory in which the Dart script (which is currently running) is located. How do I go about doing this?

Previously, this was possible through new Options().script, but that class is no more. The arguments list from main(args) doesn't help, since it only contains arguments, not the executed Dart file (at least on Mac OS X).

回答1:

According to BREAKING CHANGE: dart:io Platform and Options are deprecated, and will be removed and Breaking Change: Platform.script is a Uri, dart:platform library is gone new Options().script should be replaced by Platform.script.

Note that Platform.script returns an Uri and you should consider using toFilePath to get the file path from the file URI.



标签: dart