Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get path to directory from which script has been started

Tags:

dart

dart-io

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?

like image 895
J Sorel Avatar asked Apr 24 '26 08:04

J Sorel


1 Answers

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?

like image 146
Günter Zöchbauer Avatar answered Apr 26 '26 23:04

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!