J Sorel
J Sorel

Reputation: 353

Get path to directory from which script has been started

For example, I have this structure:

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

How I can get a path to the folder from which the script has been started? For example, I start main.dart from /home/user folder by:

dart app/bin/main.dart

Inside main.dart I need get the path /home/user. Is this possible?

Upvotes: 3

Views: 1226

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657058

I assume this is what you are looking for.

import 'dart:io';

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

  // or

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

see also How do I get the script path in Dart?

Upvotes: 4

Related Questions