Skip to content

PathOpener

Category: Core

Source: path_opener.dart

Opens local directories in the OS file manager.

Platform-agnostic wrapper over the usual reveal-a-folder commands:

  • macOS: open <dir> (argv, no shell)
  • Windows: explorer <dir> (argv, no shell)
  • other: xdg-open <dir> (Linux, BSD, Unix-likes)

Paths are validated before launch: control chars and a set of shell metacharacters (& | ^ < > " \ ` $) are rejected as defence in depth, even though we never pass the path through a shell. Non-ASCII characters are allowed — home directories with accented names are common.

The runner and existence check are injectable so tests don't spawn real processes or touch the real filesystem.

Functions

`Future<bool> openInFileManager(

String dir, { ProcessRunner? runner, DirectoryExistsCheck? directoryExists, })`

Open [dir] in the OS file manager. Returns false (never throws) when:

  • [dir] is empty, contains shell metacharacters, or control chars
  • [dir] does not exist as a directory
  • the launched command exits non-zero
  • the launcher itself throws (ProcessException, etc.)

Released under the MIT License.