1

I want to check if String is valid as a local path in Dart, (It doesn't matter whether the path exists or not), I want to check if the String is valid to be used as a local path or not.

similar question with Python

Ayad Salim
  • 88
  • 7
  • In general, whether a path is valid depends on the file system. As there are many possible file systems (even for a single platform), the only real way to tell if a path would be valid is to actually try using it. – jamesdlin Feb 28 '22 at 15:35

1 Answers1

1

File

Async
    File("yourfile").exists()

sync
    File("/sdcard/").existsSync()

Directory

  Directory("your directory").exists()
  Directory("/sdcard/").existsSync()

use with try catch

Both cases you need android permission to access the file otherwise you will get a file or directory or path not exist exception. if already file exist

lava
  • 6,020
  • 2
  • 31
  • 28