Filesystem

This module must be enabled under "Plugins" in the Deskifier Dashboard

Methods

Request Download

Requests a download to the device. When the download starts, the Download Started event will fire.

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

Arguments

  • url String (Required)
    The file to download. Must be from a https domain.
  • dialogOptions Electron.SaveDialogOptions (Optional)
    Optional "save as" dialog options, to customize the dialog window that is shown.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful.

Pause Download

Pauses an active download.

Some paused downloads may not be able to be resumed, depending on the web server. In this case, the download will restart.

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

Arguments

  • downloadId String (Required)

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful.

Resume Download

Resumes a paused download.

Some paused downloads may not be able to be resumed, depending on the web server. In this case, the download will restart.

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

Arguments

  • downloadId String (Required)

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful.

Cancel Download

Cancels a download.

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

Arguments

  • downloadId String (Required)

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful.

Read Directory

Reads the contents of the given directory.

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

Arguments

  • path String (Required)
    Which directory to read. Will return an error if directory can't be found.

Returns

  • files Array
    • name String
      Name of the file.
    • isDirectory Boolean
    • isFile Boolean
    • fileExtension String
    • directory String
    • fullPath String
  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful.

Example

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'
        }
    ]
*/

Create Directory

Creates a new directory in a given directory.

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

Arguments

  • path String (Required)
    Where to create the new directory.
  • dirName String (Required)
    The new name of the directory.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful.

Example

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

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

Upload File

Sets the value of a file uploader input.

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.

Limited to whitelisted directories, without custom code signing certificates.

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

Arguments

  • windowID String (Optional)
    Which Deskifier window to target. Defaults to the sender window.
  • filePaths Array of Strings (Required)
    Which files to upload.
  • selector String (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 Boolean
    If the action was successful.
  • message String
    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>


Show In Folder

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

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

Arguments

  • path String (Required)

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful.

Trash File

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

Limited to whitelisted directories, without custom code signing certificates.

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

Arguments

  • path String (Required)
    The path of the file/directory to trash.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful

Read File

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

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 method to make sure the file is small in size.

Limited to whitelisted directories, without custom code signing certificates.

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

Arguments

  • path String (Required)
    The path of the file to read.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful
  • content String
    The file's contents, decoded as UTF-8.

Create Thumbnail

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

Limited to whitelisted directories, without custom code signing certificates.

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

Arguments

  • path String (Required)
    The path of the file to generate a thumbnail for.
  • size Object (Required)
    Target dimensions for the thumbnail.
    • width Number
    • height Number

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful
  • dataURL String
    Base64-encoded image data URL of the thumbnail.

Create File

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

Limited to whitelisted directories, without custom code signing certificates.

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

Arguments

  • path String (Required)
    The path of the new file. The function will fail if a file already exists at the given path.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful
  • filePath String
    The path to the newly created file.

Write File

Overwrites a file's contents.

This method isn't intended for large files, rather smaller files like .json or .txt files.

Limited to whitelisted directories, without custom code signing certificates.

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

Arguments

  • path String (Required)
    The path of the file to write to.
  • content String (Required)
    What to write to the file.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful

Rename File

Renames a file or directory.

Limited to whitelisted directories, without custom code signing certificates.

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

Arguments

  • path String (Required)
    The path of the file to rename.
  • newFileName String (Required)
    The name of the new file.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful

Move File

Moves a file or directory from one location to another.

Limited to whitelisted directories, without custom code signing certificates.

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

Arguments

  • path String (Required)
    The path of the file to move.
  • destinationPath String (Required)
    Where to move the file to.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful

Get File Stats

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

Limited to whitelisted directories, without custom code signing certificates.

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

Arguments

  • path String (Required)
    The path of the file to check.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful
  • stats Object
    • size Number
      File size in bytes.
    • sizeHuman String
      File size as readable format (ex. "1mb")
    • path String
      Absolute path to the file.
    • extension String
      File extension including the leading dot (ex. ".txt").
    • parentDirectory String
    • fileName String
    • isFile Boolean
    • isDirectory Boolean
    • createdAt String
      ISO-formatted creation timestamp.
    • modifiedAt String
      ISO-formatted modification timestamp.
    • accessedAt String
      ISO-formatted last-access timestamp.

Check Access

Checks permissions for a given file or directory

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

Arguments

  • path String (Required)
    The path of the file/directory to check.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful
  • permissions Object
    • readable Boolean
    • writable Boolean
    • executable Boolean
  • isInAllowedDirectory Boolean
    Whether the path is inside Deskifier's filesystem access allowlist.

Watch Path

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

Be sure to "unwatch" when a watch is no longer needed, for performance reasons.

Limited to whitelisted directories, without custom code signing certificates.

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

Arguments

  • path String (Required)
    The path of the file/directory to watch.
  • recursive Boolean (Optional)
    Specify if all the subdirectories of the given directory should be watched. The default value is false.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful
  • watchId String
    The ID of the watch job.

Unwatch Path

Stops observing a file/directory for changes.

Be sure to "unwatch" when a watch is no longer needed, for performance reasons.

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

Arguments

  • watchId String (Required)

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful

Node Path Tools

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

Basename
Extracts the last part of a path (the filename).

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

Extname
Extracts the file extension (including the leading dot).

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

Join
Joins path segments together, using the platform-specific separator.

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

Relative
Finds the relative path between one path and another.

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

Normalize
Resolves incorrect platform-specific separators, resolves .. (parent directory) and . (current directory) segments, and handles extra separators.

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

Resolve
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.

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

Dirname
Returns the directory name of a path. This is equivalent to removing the last part of a path.

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

Separator
Returns the platform-specific path segment separator
\ on Windows
/ on POSIX

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

Examples

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

Properties

Get Default Directories

Returns the default directories of the device.

These directories are whitelisted.

await window.deskifier.filesystem.getDefaultDirectories()

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful
  • directories Object
    • desktop String
    • documents String
    • downloads String
    • music String
    • pictures String
    • videos String
    • appData String
    • temp String
    • exe String
      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>


Get Drives

Returns the available storage drives, and information about them.

await window.deskifier.filesystem.getDrives()

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful
  • drives Array of Objects
    • available Number
      Amount of storage available, in bytes.
    • used Number
      Amount of storage used, in bytes.
    • size Number
      Total size of the disk or partition, in bytes.
    • capacity String
      Percent of the drive/partition that is utilized.
    • filesystem String
      The type of storage.
    • mounted String
      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>


Get Allowed Paths

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

await window.deskifier.filesystem.getAllowedPaths()

Returns

  • success Boolean
    If the action was successful.
  • directoryRoots Array of Strings
    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 Strings
    Specific file paths the user has granted access to (via open dialogs, drag-and-drop, etc.).
  • explicitDirectories Array of Strings
    Specific directories the user has granted access to.

Events

Download Started

Fires when a download starts.

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

Arguments

  • id String
    The download ID.
  • savePath String
    Where the download is being saved to.
  • fileName String
    The name of the file being downloaded.
  • mimeType String
    The type of file being downloaded.
  • state String
    Can be progressing, completed, cancelled or interrupted.
  • percentCompleted Number
    Percent out of 100
  • transferredBytes Number
  • totalBytes Number
    Download size in bytes. If the size is unknown, it returns 0.
  • speed Number
    Download speed in bytes per second.

Download Updated

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

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

Arguments

  • id String
    The download ID.
  • savePath String
    Where the download is being saved to.
  • fileName String
    The name of the file being downloaded.
  • mimeType String
    The type of file being downloaded.
  • state String
    Can be progressing, completed, cancelled , paused or interrupted.
  • percentCompleted Number
    Percent out of 100
  • transferredBytes Number
  • totalBytes Number
    Download size in bytes. If the size is unknown, it returns 0.
  • speed Number
    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); }); <strong> </strong>/* { 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>


Download Completed

Fires only when a download successfully completes.

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

Arguments

  • id String
    The download ID.

Example

<pre class="language-javascript"><code class="lang-javascript">window.deskifier.filesystem.onDownloadCompleted((downloadData) => { console.log(downloadData); }); <strong> </strong>/* { id: 'foobar' } */ </code></pre>


Download Canceled

Fires when a download fails or is canceled.

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

Arguments

  • id String
    The download ID.
  • state String
    Can be cancelled or failed.
  • message String
    The error message, if any.

Example

<pre class="language-javascript"><code class="lang-javascript">window.deskifier.filesystem.onDownloadCanceled((downloadData) => { console.log(downloadData); }); <strong> </strong>/* { id: 'foobar', state: 'cancelled', message: 'Download was cancelled' } */ </code></pre>


Path Update

Fires when a watched path is updated.

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

Arguments

  • watchId String
    The ID of the observer.
  • path String
    The path being watched.
  • eventType String
    Can be rename or change. rename is emitted whenever a filename appears or disappears in the directory.
  • filename String
    The filename that changed. Can sometimes be null.

Example

<pre class="language-javascript"><code class="lang-javascript">window.deskifier.filesystem.onPathUpdate((data) => { console.log(data); }); <strong> </strong>/* { watchId: 'foobar', path: 'C:\Users\Example\Desktop', eventType: 'rename', filename: 'example.png' } */ </code></pre>