Julien
Julien

Reputation: 4163

dart : check if a directory exist

In Dart would like to check if a directory exist but without knowing a substring of this directory :

eg :

dir = preview/1552146038702.jpg.1--001--001.html.test.jpg

I tried :

io.Directory(await dir).exists().then((exist){

but in the dir I don't know 1--001--001.html

Any idea?

Upvotes: 11

Views: 13207

Answers (3)

Szekelygobe
Szekelygobe

Reputation: 2687

Don't forget to import :

import 'dart:io';

Upvotes: 0

Wisnu Wijokangko
Wisnu Wijokangko

Reputation: 2308

This works for me, hope my answer help

final path = '/storage/emulated/0/Download';
final checkPathExistence = await Directory(path).exists();

Upvotes: 8

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657446

Directory.exists() provides this information

bool exists = await Directory(path).exists();

Upvotes: 22

Related Questions