26

I want to know what the current directory is. I don't want to shell out to run pwd. Is there an easy way to do this in Dart?

Seth Ladd
  • 112,095
  • 66
  • 196
  • 279

2 Answers2

40

Indeed there is!

import 'dart:io';

main() {
  Directory current = Directory.current;
}

Note: this only works on the command-line, not in the browser.

Read more about the API docs for Directory.current.

Danny Tuppeny
  • 40,147
  • 24
  • 151
  • 275
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
7

Directory.current.path does it if you want a string, Directory.current for a Directory.

(note: Directory is defined in dart:io)

Tree Plate
  • 71
  • 1
  • 1
  • please note that Directory.current.path will change after using file picker. github.com/miguelpruivo/flutter_file_picker/issues/804 – Noryn Basaya Apr 08 '23 at 15:43