Pick Files

Let the user pick files through win32.run Files Picker dialog.

await win32.pick_files(desc, exts, multiple);

Params

desc

String

Description of the files you want to pick. It will be displayed to the user.

let desc = 'Whatever, any files';

exts

[String]

Acceptable file extensions, case-insensitive. Each extension starts with a dot character.

let exts = ['.txt', '.html', '.md'];

Specify an empty array [] to accept any extension

multiple

Boolean

Default to true

Whether to allow the user to select multiple or single file.

Returns

Promise<[Object]>

A promise that resolves with an array of objects. Each object has the following structure.

{
    id: String, 
    //id of the file on win32.run
    //which can be used to retrieve the file later 
    //without invoking the Files Picker dialog. See Get File section

    win32_name: String, 
    //display name of the file on win32.run. 
    //could be different to name in file.name

    win32_path: String, 
    //path of the file on win32.run. 
    //it just for display purpose (like in My Computer). 
    //GET request to win32_path will not return the file content

    file: File
    //a File object, 
    //see https://developer.mozilla.org/en-US/docs/Web/API/File
}

This method will always return a promise of an array, regardless of the multiple value

Example

let results = await win32.pick_files('Any plain text files', ['.txt', '.html', '.md'], true);

//read text content of the first file using File.text()
let content = await results[0].file.text();

Last updated