如何获取Dart中的脚本路径? [英] How do I get the script path in Dart?

查看:487
本文介绍了如何获取Dart中的脚本路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找出Dart脚本(当前运行)所在的目录。

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?

以前,这可以通过新的Options()。script 那个类就没有了。 main(args)的参数列表没有帮助,因为它只包含参数,而不是执行的Dart文件(至少在Mac OS X上)。

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).

推荐答案

根据 BREAKING CHANGE:dart:io平台和选项已弃用,将被删除破解更改:Platform.script是一个Uri,dart:平台库已过 ().script 应替换为 Platform.script

code> Platform.script 返回 Uri ,您应该考虑使用 toFilePath 从文件URI中获取文件路径。

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

这篇关于如何获取Dart中的脚本路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆