获取已启动脚本的目录的路径

时间:2015-03-03 19:57:37

标签: dart dart-io

例如,我有这样的结构:

/home/user <- my current dir
/home/user/app/bin/main.dart <- entry point of my application

如何获取启动脚本的文件夹的路径?例如,我从main.dart文件夹中启动/home/user

dart app/bin/main.dart

main.dart内,我需要获取路径/home/user。这可能吗?

1 个答案:

答案 0 :(得分:4)

我认为这就是你要找的东西。

import 'dart:io';

void main() {
  print(Platform.script);
  print(Platform.script.toFilePath(windows: true));

  // or

  print(Directory.current.absolute.path);
}

另见How do I get the script path in Dart?