Skip to content

@jsvision/files / openFile

Function: openFile()

openFile(host, opts?): Promise<string | null>

Defined in: files/src/openers.ts:60

Show a modal file dialog and resolve to the chosen absolute path, or null if the user cancels.

Parameters

host

ExecHost

A host that can run a view modally — the createApplication result works directly.

opts?

OpenFileOptions = {}

Filesystem, starting directory/wildcard, open/save mode, and title.

Returns

Promise<string | null>

The chosen absolute path, or null on cancel.

Example

ts
import { createApplication } from '@jsvision/ui';
import { resolveCapabilities } from '@jsvision/core';
import { openFile } from '@jsvision/files';

const caps = resolveCapabilities({ env: process.env, platform: process.platform }).profile;
const app = createApplication({ caps });

const path = await openFile(app, { directory: '/home/user', wildcard: '*.ts' });
if (path !== null) console.log('chosen', path);