Get script path in Dart (analog __DIR__ constant in PHP)

后端 未结 3 1175
眼角桃花
眼角桃花 2020-12-12 00:57

How I can get path of the current script (not executable) in Dart?

For example. In PHP we have __DIR__ constant, that reffer to script directory. If we

3条回答
  •  春和景丽
    2020-12-12 01:20

    You've said that when you run test.dart, the current directory is /path/to/lib/tests. So you should be able to use a relative path to open rules.json. The path is ../rules/rules.json (or of course, ..\rules\rules.json on Windows, you can get the separator from Platform.pathSeparator).

    Alternately, apparently you can get a Uri for the current script (if supported by the platform) from Platform.script.

提交回复
热议问题