How do I get the directory of the current script, in Dart?


I want to know what the script’s directory is. I have a command-line Dart script.


The easiest way to find the script’s directory is to use the path package.

import "package:path/path.dart" show dirname;
import 'dart:io' show Platform;

main() {

Put the path package into your pubspec.yaml:

  path: any

And be sure to run pub get to download and link the path package.

Answered By – Seth Ladd

Answer Checked By – Terry (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *