# Filesystem

{% hint style="warning" %}
This module must be enabled under "Plugins" in the Deskifier Dashboard
{% endhint %}

## Methods

### <mark style="color:purple;">Request Download</mark>

Requests a download to the device. When the download starts, the [Download Started](#download-started) event will fire.

{% tabs %}
{% tab title="Javascript" %}

```javascript
await window.deskifier.filesystem.requestDownload({ arguments })
```

**Arguments**

* `url` <mark style="color:green;">String</mark> (Required)\
  The file to download. Must be from a https domain.
* `dialogOptions` [<mark style="color:blue;">Electron.SaveDialogOptions</mark>](https://www.electronjs.org/docs/latest/api/dialog#dialogshowsavedialogwindow-options) (Optional)\
  Optional "save as" dialog options, to customize the dialog window that is shown.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Pause Download</mark>

Pauses an active download.

{% hint style="warning" %}
Some paused downloads may not be able to be resumed, depending on the web server. In this case, the download will restart.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.filesystem.pauseDownload({ arguments })
```

**Arguments**

* `downloadId` <mark style="color:green;">String</mark> (Required)

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Resume Download</mark>

Resumes a paused download.

{% hint style="warning" %}
Some paused downloads may not be able to be resumed, depending on the web server. In this case, the download will restart.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.filesystem.resumeDownload({ arguments })
```

**Arguments**

* `downloadId` <mark style="color:green;">String</mark> (Required)

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Cancel Download</mark>

Cancels a download.

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>await window.deskifier.filesystem.cancelDownload({ arguments })
</strong></code></pre>

**Arguments**

* `downloadId` <mark style="color:green;">String</mark> (Required)

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Read Directory</mark>

Reads the contents of the given directory.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.filesystem.readDirectory({ arguments })
```

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)\
  Which directory to read. Will return an error if directory can't be found.

**Returns**

* `files` <mark style="color:green;">Array</mark>
  * `name` <mark style="color:green;">String</mark>\
    Name of the file.
  * `isDirectory` <mark style="color:green;">Boolean</mark>
  * `isFile` <mark style="color:green;">Boolean</mark>
  * `fileExtension` <mark style="color:green;">String</mark>
  * `directory` <mark style="color:green;">String</mark>
  * `fullPath` <mark style="color:green;">String</mark>
* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.

**Example**

{% code overflow="wrap" %}

```javascript
const files = await window.deskifier.filesystem.readDirectory({ path: directory });
console.log(files.files)
/*
    [
        {
            name: 'example.txt',
            isDirectory: false,
            isFile: true,
            fileExtension: '.txt',
            directory: 'C:/Users/Example/Documents',
            fullPath: 'C:/Users/Example/Documents/example.txt'
        },
        {
            name: 'images',
            isDirectory: true,
            isFile: false,
            fileExtension: '',
            directory: 'C:/Users/Example/Documents',
            fullPath: 'C:/Users/Example/Documents/images'
        }
    ]
*/
```

{% endcode %}
{% endtab %}
{% endtabs %}

***

### <mark style="color:purple;">Create Directory</mark>

Creates a new directory in a given directory.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.filesystem.createDirectory({ arguments })
```

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)\
  Where to create the new directory.
* `dirName` <mark style="color:green;">String</mark> (Required)\
  The new name of the directory.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.

**Example**

{% code overflow="wrap" %}

```javascript
const args = {
            path: "C:\\Users\\Example\\Desktop",
            dirName: "Example Folder"
        };

await window.deskifier.filesystem.createDirectory(args);
```

{% endcode %}
{% endtab %}
{% endtabs %}

***

### <mark style="color:purple;">Upload File</mark>

Sets the value of a file uploader input.

{% hint style="info" %}
Instead of handling the process of uploading the file from the device to the destination, this function allows you to set the value of a web file uploader programmatically.\
\
This isn't normally possible in browsers, however, the electron app has special capabilities enabled to override these restrictions.\
\
This allows developers to use existing file upload methods; it improves the reliability of file uploads and makes handling errors easier.
{% endhint %}

{% hint style="danger" %}
Limited to [whitelisted](#get-default-directories) directories, without custom code signing certificates.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.filesystem.uploadFile({ arguments })
```

**Arguments**

* `windowID` <mark style="color:green;">String</mark> (Optional)\
  Which Deskifier window to target. Defaults to the sender window.
* `filePaths` <mark style="color:green;">Array of</mark> <mark style="color:green;">Strings</mark> (Required)\
  Which files to upload.
* `selector` <mark style="color:green;">String</mark> (Required)\
  The selector of the input. If multiple matches are found, the first item will be used. Will return an error if a file uploader input can't be found.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.

**Example**

<pre class="language-javascript" data-overflow="wrap"><code class="lang-javascript"><strong>window.deskifier.filesystem.uploadFile({
</strong>        windowID: "window-1",
        filePaths: ['C:\\Users\\Example\\Desktop\\exampleFile.png'],
        selector: '#fileUploader'
    })
</code></pre>

{% endtab %}
{% endtabs %}

***

### <mark style="color:purple;">Show In Folder</mark>

Attempts to show the given file in a file manager, and if possible, selects the file.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.filesystem.showInFolder({ arguments })
```

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Trash File</mark>

Attempts to move a file or directory to the recycle bin.

{% hint style="danger" %}
Limited to [whitelisted](#get-default-directories) directories, without custom code signing certificates.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>await window.deskifier.filesystem.trashFile({ arguments })
</strong></code></pre>

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)\
  The path of the file/directory to trash.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Read File</mark>

Attempts to read the file, and return data as a string.

{% hint style="danger" %}
This reads the full content of the file in memory before returning the data.

This means that big files are going to have a major impact on your memory consumption and can lead to crashes.\
\
Use this in tandem with the [Get Stats](#get-file-stats) method to make sure the file is small in size.
{% endhint %}

{% hint style="danger" %}
Limited to [whitelisted](#get-default-directories) directories, without custom code signing certificates.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>await window.deskifier.filesystem.readFile({ arguments })
</strong></code></pre>

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)\
  The path of the file to read.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
* `content` <mark style="color:green;">String</mark>\
  The file's contents, decoded as UTF-8.
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Create Thumbnail</mark>

Creates a thumbnail from the file, and returns it as base64. Can be used to preview images & videos.

{% hint style="danger" %}
Limited to [whitelisted](#get-default-directories) directories, without custom code signing certificates.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>await window.deskifier.filesystem.createThumbnail({ arguments })
</strong></code></pre>

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)\
  The path of the file to generate a thumbnail for.
* `size` <mark style="color:green;">Object</mark> (Required)\
  Target dimensions for the thumbnail.
  * `width` <mark style="color:green;">Number</mark>
  * `height` <mark style="color:green;">Number</mark>

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
* `dataURL` <mark style="color:green;">String</mark>\
  Base64-encoded image data URL of the thumbnail.
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Create File</mark>

Creates an empty file, for you to write data to.

{% hint style="danger" %}
Limited to [whitelisted](#get-default-directories) directories, without custom code signing certificates.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>await window.deskifier.filesystem.createFile({ arguments })
</strong></code></pre>

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)\
  The path of the new file. The function will fail if a file already exists at the given path.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
* `filePath` <mark style="color:green;">String</mark>\
  The path to the newly created file.
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Write File</mark>

Overwrites a file's contents.

{% hint style="info" %}
This method isn't intended for large files, rather smaller files like .json or .txt files.
{% endhint %}

{% hint style="danger" %}
Limited to [whitelisted](#get-default-directories) directories, without custom code signing certificates.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>await window.deskifier.filesystem.writeFile({ arguments })
</strong></code></pre>

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)\
  The path of the file to write to.
* `content` <mark style="color:green;">String</mark> (Required)\
  What to write to the file.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Rename File</mark>

Renames a file or directory.

{% hint style="danger" %}
Limited to [whitelisted](#get-default-directories) directories, without custom code signing certificates.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>await window.deskifier.filesystem.renameFile({ arguments })
</strong></code></pre>

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)\
  The path of the file to rename.
* `newFileName` <mark style="color:green;">String</mark> (Required)\
  The name of the new file.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
  {% endtab %}
  {% endtabs %}

### <mark style="color:purple;">Move File</mark>

Moves a file or directory from one location to another.

{% hint style="danger" %}
Limited to [whitelisted](#get-default-directories) directories, without custom code signing certificates.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>await window.deskifier.filesystem.moveFile({ arguments })
</strong></code></pre>

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)\
  The path of the file to move.
* `destinationPath` <mark style="color:green;">String</mark> (Required)\
  Where to move the file to.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Get File Stats</mark>

Gets stats about the file like size, creation date, etc.

{% hint style="danger" %}
Limited to [whitelisted](#get-default-directories) directories, without custom code signing certificates.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>await window.deskifier.filesystem.getStats({ arguments })
</strong></code></pre>

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)\
  The path of the file to check.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
* `stats` <mark style="color:green;">Object</mark>
  * `size` <mark style="color:green;">Number</mark>\
    File size in bytes.
  * `sizeHuman` <mark style="color:green;">String</mark>\
    File size as readable format (ex. "1mb")
  * `path` <mark style="color:green;">String</mark>\
    Absolute path to the file.
  * `extension` <mark style="color:green;">String</mark>\
    File extension including the leading dot (ex. ".txt").
  * `parentDirectory` <mark style="color:green;">String</mark>
  * `fileName` <mark style="color:green;">String</mark>
  * `isFile` <mark style="color:green;">Boolean</mark>
  * `isDirectory` <mark style="color:green;">Boolean</mark>
  * `createdAt` <mark style="color:green;">String</mark>\
    ISO-formatted creation timestamp.
  * `modifiedAt` <mark style="color:green;">String</mark>\
    ISO-formatted modification timestamp.
  * `accessedAt` <mark style="color:green;">String</mark>\
    ISO-formatted last-access timestamp.
    {% endtab %}
    {% endtabs %}

***

### <mark style="color:purple;">Check Access</mark>

Checks permissions for a given file or directory

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>await window.deskifier.filesystem.checkAccess({ arguments })
</strong></code></pre>

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)\
  The path of the file/directory to check.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
* `permissions` <mark style="color:green;">Object</mark>
  * `readable` <mark style="color:green;">Boolean</mark>
  * `writable` <mark style="color:green;">Boolean</mark>
  * `executable` <mark style="color:green;">Boolean</mark>
* `isInAllowedDirectory` <mark style="color:green;">Boolean</mark>\
  Whether the path is inside Deskifier's filesystem access allowlist.
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Watch Path</mark>

Watches a directory or file for changes. Will fire the Path Changed event.

{% hint style="warning" %}
Be sure to "unwatch" when a watch is no longer needed, for performance reasons.
{% endhint %}

{% hint style="danger" %}
Limited to [whitelisted](#get-default-directories) directories, without custom code signing certificates.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>await window.deskifier.filesystem.watch({ arguments })
</strong></code></pre>

**Arguments**

* `path` <mark style="color:green;">String</mark> (Required)\
  The path of the file/directory to watch.
* `recursive` <mark style="color:green;">Boolean</mark> (Optional)\
  Specify if all the subdirectories of the given directory should be watched. The default value is false.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
* `watchId` <mark style="color:green;">String</mark>\
  The ID of the watch job.
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Unwatch Path</mark>

Stops observing a file/directory for changes.

{% hint style="warning" %}
Be sure to "unwatch" when a watch is no longer needed, for performance reasons.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>await window.deskifier.filesystem.unwatch({ arguments })
</strong></code></pre>

**Arguments**

* `watchId` <mark style="color:green;">String</mark> (Required)

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Node Path Tools</mark>

A collection of node.js path tools to help modify & construct paths.

{% tabs %}
{% tab title="JavaScript" %}
[**Basename**](https://nodejs.org/api/path.html#pathbasenamepath-suffix)\
Extracts the last part of a path (the filename).

```javascript
await window.deskifier.filesystem.path.basename(path, [ext])
```

[**Extname**](https://nodejs.org/api/path.html#pathextnamepath)\
Extracts the file extension (including the leading dot).

```javascript
await window.deskifier.filesystem.path.extname(path)
```

[**Join**](https://nodejs.org/api/path.html#pathjoinpaths)\
Joins path segments together, using the platform-specific separator.

```javascript
await window.deskifier.filesystem.path.join(...paths)
```

[**Relative**](https://nodejs.org/api/path.html#pathrelativefrom-to)\
Finds the relative path between one path and another.

```javascript
await window.deskifier.filesystem.path.relative(from, to)
```

[**Normalize**](https://nodejs.org/api/path.html#pathnormalizepath)\
Resolves incorrect platform-specific separators, resolves `..` (parent directory) and `.` (current directory) segments, and handles extra separators.

```javascript
await window.deskifier.filesystem.path.normalize(path)
```

[**Resolve**](https://nodejs.org/api/path.html#pathresolvepaths)\
Resolves a sequence of paths or path segments into an absolute path. It treats each argument from right to left, prepending it to the path until an absolute path is constructed.

```javascript
await window.deskifier.filesystem.path.resolve(...pathSegments)
```

[**Dirname**](https://nodejs.org/api/path.html#pathdirnamepath)\
Returns the directory name of a path. This is equivalent to removing the last part of a path.

```javascript
await window.deskifier.filesystem.path.dirname(path)
```

[<mark style="color:blue;">**Separator**</mark>](https://nodejs.org/api/path.html#pathsep)\
Returns the platform-specific path segment separator\
`\` on Windows\
`/` on POSIX

```javascript
await window.deskifier.filesystem.path.sep()
```

**Examples**

{% code overflow="wrap" %}

```javascript
await window.deskifier.filesystem.path.basename('C:\\Users\\Example\\file.txt');
//file.txt

await window.deskifier.filesystem.path.extname('C:\\Users\\Example\\file.txt');
//.txt

await window.deskifier.filesystem.path.join('Users', 'Example', 'file.txt');
//C:\\Users\\Example\\file.txt

await window.deskifier.filesystem.path.relative('C:\\Users\\Example\\file.txt', 'C:\\Users\\User\\file.txt');
//..\\..\\User\\file.txt

await window.deskifier.filesystem.path.normalize('C:/Users/Example/file.txt');
//C:\\Users\\Example\\file.txt

await window.deskifier.filesystem.path.resolve('C:\\Users\\Example','example.txt');
//C:\\Users\\Example\\example.txt

await window.deskifier.filesystem.path.dirname('C:\\Users\\Example');
//C:\\Users
```

{% endcode %}
{% endtab %}
{% endtabs %}

***

## Properties

### <mark style="color:purple;">Get Default Directories</mark>

Returns the default directories of the device.

{% hint style="info" %}
These directories are whitelisted.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.filesystem.getDefaultDirectories()
```

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
* `directories` <mark style="color:green;">Object</mark>
  * `desktop` <mark style="color:green;">String</mark>
  * `documents` <mark style="color:green;">String</mark>
  * `downloads` <mark style="color:green;">String</mark>
  * `music` <mark style="color:green;">String</mark>
  * `pictures` <mark style="color:green;">String</mark>
  * `videos` <mark style="color:green;">String</mark>
  * `appData` <mark style="color:green;">String</mark>
  * `temp` <mark style="color:green;">String</mark>
  * `exe` <mark style="color:green;">String</mark>\
    Path to the running Deskifier executable.

**Example**

<pre class="language-javascript"><code class="lang-javascript">const directories = await window.deskifier.filesystem.getDefaultDirectories();
<strong>console.log(directories.directories)
</strong>/*
{
  desktop: 'C:\\Users\\Example\\Desktop',
  documents: 'C:\\Users\\Example\\Documents',
  downloads: 'C:\\Users\\Example\\Downloads',
  music: 'C:\\Users\\Example\\Music',
  pictures: 'C:\\Users\\Example\\Pictures',
  videos: 'C:\\Users\\Example\\Videos',
  appData: 'C:\\Users\\Example\\AppData\\Roaming',
  temp: 'C:\\Users\\Example\\AppData\\Local\\Temp',
  exe: 'C:\\Users\\Example\\Program Files\\DesktopApp\\app.exe'
}
*/
</code></pre>

{% endtab %}
{% endtabs %}

***

### <mark style="color:purple;">Get Drives</mark>

Returns the available storage drives, and information about them.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.filesystem.getDrives()
```

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful
* `drives` <mark style="color:green;">Array of Objects</mark>
  * `available` <mark style="color:green;">Number</mark>\
    Amount of storage available, in bytes.
  * `used` <mark style="color:green;">Number</mark>\
    Amount of storage used, in bytes.
  * `size` <mark style="color:green;">Number</mark>\
    Total size of the disk or partition, in bytes.
  * `capacity` <mark style="color:green;">String</mark>\
    Percent of the drive/partition that is utilized.
  * `filesystem` <mark style="color:green;">String</mark>\
    The type of storage.
  * `mounted` <mark style="color:green;">String</mark>\
    Location in the filesystem where the storage device is accessible.

**Example**

<pre class="language-javascript"><code class="lang-javascript">const drives = await window.deskifier.filesystem.getDrives();
<strong>console.log(drives.drives)
</strong>/*
    [
        {
            filesystem: 'Local Fixed Disk',
            size: 119387713536,
            used: 109906608128,
            available: 9481105408,
            capacity: '92%',
<strong>            mounted: 'C:\\'
</strong>        },
        {
            filesystem: 'CD-ROM Drive',
            size: 0,
            used: 0,
            available: 0,
            capacity: '0%',
            mounted: 'E:\\'
        }
    ]
    */
</code></pre>

{% endtab %}
{% endtabs %}

***

### <mark style="color:purple;">Get Allowed Paths</mark>

Returns the current filesystem allowlist — the directories, specific files, and individual folders the app is permitted to read/write. Useful for debugging permission errors.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.filesystem.getAllowedPaths()
```

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `directoryRoots` Array of <mark style="color:green;">Strings</mark>\
  Root directories the app has broad access to (e.g. default folders like Documents/Downloads, plus any custom roots granted via the Deskifier dashboard).
* `explicitFiles` Array of <mark style="color:green;">Strings</mark>\
  Specific file paths the user has granted access to (via open dialogs, drag-and-drop, etc.).
* `explicitDirectories` Array of <mark style="color:green;">Strings</mark>\
  Specific directories the user has granted access to.
  {% endtab %}
  {% endtabs %}

***

## Events

### <mark style="color:purple;">Download Started</mark>

Fires when a download starts.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
window.deskifier.filesystem.onDownloadStarted((downloadData) => {})
```

**Arguments**

* `id` <mark style="color:green;">String</mark>\
  The download ID.
* `savePath` <mark style="color:green;">String</mark>\
  Where the download is being saved to.
* `fileName` <mark style="color:green;">String</mark>\
  The name of the file being downloaded.
* `mimeType` <mark style="color:green;">String</mark>\
  The type of file being downloaded.
* `state` <mark style="color:green;">String</mark>\
  Can be `progressing`, `completed`, `cancelled` or `interrupted`.
* `percentCompleted` <mark style="color:green;">Number</mark>\
  Percent out of 100
* `transferredBytes` <mark style="color:green;">Number</mark>
* `totalBytes` <mark style="color:green;">Number</mark>\
  Download size in bytes. If the size is unknown, it returns 0.
* `speed` <mark style="color:green;">Number</mark>\
  Download speed in bytes per second.
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Download Updated</mark>

Fires periodically when there is an update to the download (ex. progress update, paused/resumed events, download failed, etc.)

{% tabs %}
{% tab title="JavaScript" %}

```javascript
window.deskifier.filesystem.onDownloadUpdated((downloadData) => {})
```

**Arguments**

* `id` <mark style="color:green;">String</mark>\
  The download ID.
* `savePath` <mark style="color:green;">String</mark>\
  Where the download is being saved to.
* `fileName` <mark style="color:green;">String</mark>\
  The name of the file being downloaded.
* `mimeType` <mark style="color:green;">String</mark>\
  The type of file being downloaded.
* `state` <mark style="color:green;">String</mark>\
  Can be `progressing`, `completed`, `cancelled` , `paused` or `interrupted`.
* `percentCompleted` <mark style="color:green;">Number</mark>\
  Percent out of 100
* `transferredBytes` <mark style="color:green;">Number</mark>
* `totalBytes` <mark style="color:green;">Number</mark>\
  Download size in bytes. If the size is unknown, it returns 0.
* `speed` <mark style="color:green;">Number</mark>\
  Download speed in bytes per second.

**Example**

<pre class="language-javascript"><code class="lang-javascript"><strong>window.deskifier.filesystem.onDownloadUpdated((downloadData) => {
</strong>    console.log(downloadData);
});

/*
{
        id: '6a191b',
        savePath: "C:\\Users\\Example\\Downloads\\renamedExample.zip",
        fileName: "example.zip",
        mimeType: "application/zip"
        state: 'progressing',
        percentCompleted: 27.5,
        transferredBytes: 28835737,
        totalBytes: 104857600,
        speed: 524288
}
*/
</code></pre>

{% endtab %}
{% endtabs %}

***

### <mark style="color:purple;">Download Completed</mark>

Fires only when a download successfully completes.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
window.deskifier.filesystem.onDownloadCompleted((downloadData) => {})
```

**Arguments**

* `id` <mark style="color:green;">String</mark>\
  The download ID.

**Example**

```javascript
window.deskifier.filesystem.onDownloadCompleted((downloadData) => {
    console.log(downloadData);
});

/*
{
        id: 'foobar'
}
*/
```

{% endtab %}
{% endtabs %}

***

### <mark style="color:purple;">Download Canceled</mark>

Fires when a download fails or is canceled.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
window.deskifier.filesystem.onDownloadCanceled((downloadData) => {})
```

**Arguments**

* `id` <mark style="color:green;">String</mark>\
  The download ID.
* `state` <mark style="color:green;">String</mark>\
  Can be `cancelled` or `failed`.
* `message` <mark style="color:green;">String</mark>\
  The error message, if any.

**Example**

```javascript
window.deskifier.filesystem.onDownloadCanceled((downloadData) => {
    console.log(downloadData);
});

/*
{
        id: 'foobar',
        state: 'cancelled',
        message: 'Download was cancelled'
}
*/
```

{% endtab %}
{% endtabs %}

***

### <mark style="color:purple;">Path Update</mark>

Fires when a watched path is updated.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
window.deskifier.filesystem.onPathUpdate((data) => {})
```

**Arguments**

* `watchId` <mark style="color:green;">String</mark>\
  The ID of the observer.
* `path` <mark style="color:green;">String</mark>\
  The path being watched.
* `eventType` <mark style="color:green;">String</mark>\
  Can be `rename` or `change`. `rename` is emitted whenever a filename appears or disappears in the directory.
* `filename` <mark style="color:green;">String</mark>\
  The filename that changed. Can sometimes be `null`.

**Example**

```javascript
window.deskifier.filesystem.onPathUpdate((data) => {
    console.log(data);
});

/*
{
        watchId: 'foobar',
        path: 'C:\\Users\\Example\\Desktop',
        eventType: 'rename',
        filename: 'example.png'
}
*/
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://deskifier.gitbook.io/deskifier/filesystem.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
