18

This seems a bit cumbersome

var fileExists = 
    new File(path).existsSync() || 
    new Directory(path).existsSync() || 
    new Link(path).existsSync() 

Is there a shorter or better way?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567

1 Answers1

38

A shorter way is

import 'dart:io';

FileSystemEntity.typeSync(path) != FileSystemEntityType.notFound

See also https://github.com/dart-lang/sdk/issues/2883#issuecomment-108317456

Empty2k12
  • 475
  • 12
  • 34
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567