Skip to main content

api.getFile()

Description

Allows getting data for a file or folder

Usage

api.getFile (
id: string
): object;

Parameters

  • id - the requested file ID

Returns

An object that is returned has the following parameters:

  • id(string) - (required) the ID of an item
  • date - (required) the Date object that represents the date of the entity
  • type - (optional) the type which can be "file" or "folder"
  • lazy - (optional) when set to true for the "folder" items, indicates that their content needs to be requested separately
  • parent (string) - (optional) the parent folder of an item for which data is provided
  • name (string) - (optional) the name of a file/folder
  • ext (string) - (optional) - file extension
  • open (boolean) - (optional) if set to true, the folder that is added will be opened; otherwise, false
  • data (array) - (optional) an array of objects with data for other items with the same parameters listed above for the item object

The object that is returned is as in the example below:

data:null
date:Thu Nov 30 2023 06:13:00 GMT+0300 {}
ext:"txt"
id:"/Info.txt"
name:"Info.txt"
parent:"/"
size:1000
type:"file"

Example

<script>
import { Filemanager } from "wx-svelte-filemanager";
import { getData } from "./common/data";

let api;

function logSelection() {
const id = api.getState().selected[0]; // get selected id
alert(api.getFile(id).name); // show the file name
}
</script>

<Filemanager
bind:api
on:select-file={logSelection} />

Related articles: