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?
Asked
Active
Viewed 1.5k times
2 Answers
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
-
2Nitpick: it's type of `Directory` not `String` :) – Kai Sellgren Oct 17 '13 at 22:35
-
@Kei Sellgren same here :-) – Mohamed Dernoun Apr 03 '20 at 19:40
-
`Directory.current.path` is the string. – Ziyad Nov 21 '21 at 10:54
-
please note that `Directory.current.path` will change after using file picker. https://github.com/miguelpruivo/flutter_file_picker/issues/804 – Noryn Basaya Apr 08 '23 at 15:43
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