Namespace: fs

cep. fs

Communicates with the computer's native file system

Source:

Members


<static, constant> ERR_CANT_READ :ErrorCode

Type:
Source:

<static, constant> ERR_CANT_WRITE :ErrorCode

Type:
Source:

<static, constant> ERR_FILE_EXISTS :ErrorCode

Type:
Source:

<static, constant> ERR_INVALID_PARAMS :ErrorCode

Type:
Source:

<static, constant> ERR_NOT_DIRECTORY :ErrorCode

Type:
Source:

<static, constant> ERR_NOT_FILE :ErrorCode

Type:
Source:

<static, constant> ERR_NOT_FOUND :ErrorCode

Type:
Source:

<static, constant> ERR_OUT_OF_SPACE :ErrorCode

Type:
Source:

<static, constant> ERR_UNKNOWN :ErrorCode

Type:
Source:

<static, constant> ERR_UNSUPPORTED_ENCODING :ErrorCode

Type:
Source:

<static, constant> NO_ERROR :ErrorCode

Type:
Source:

Methods


<static> chmod(path, mode)

Sets permissions for a file or folder.

Parameters:
Name Type Description
path string

The path of the file or folder.

mode number

The permissions in numeric format (for example, 0777).

Source:
Returns:

An object with this property:


  • "err": The status of the operation, one of:

    • NO_ERROR

    • ERR_UNKNOWN

    • ERR_INVALID_PARAMS

    • ERR_CANT_WRITE



Type
object | ErrorCode

<static> makedir(path)

Creates a new folder.

Parameters:
Name Type Description
path string

The path of the folder to create.

Source:
Returns:

An object with this property:


  • "err": The status of the operation, one of:

    • NO_ERROR

    • ERR_UNKNOWN

    • ERR_INVALID_PARAMS



Type
object | ErrorCode

<static> readdir(path)

Reads the contents of a folder.

Parameters:
Name Type Description
path string

The path of the folder to read.

Source:
Returns:

An object with these properties:


  • "data": An array of the names of the contained files (excluding '.' and '..'.

  • "err": The status of the operation, one of:

    • NO_ERROR

    • ERR_UNKNOWN

    • ERR_INVALID_PARAMS

    • ERR_NOT_FOUND

    • ERR_CANT_READ



Type
object | ErrorCode

<static> readFile(path, encoding)

Reads the entire contents of a file.

Parameters:
Name Type Description
path string

The path of the file to read.

encoding string

The encoding of the contents of file, one of
UTF8 (the default) or Base64.

Source:
Returns:

An object with these properties:


  • "data": The file contents.

  • "err": The status of the operation, one of

    • NO_ERROR

    • ERR_UNKNOWN

    • ERR_INVALID_PARAMS

    • ERR_NOT_FOUND

    • ERR_CANT_READ

    • ERR_UNSUPPORTED_ENCODING



Type
object | ErrorCode

<static> rename(oldPath, newPath)

Renames a file or folder.

Parameters:
Name Type Description
oldPath string

The old name of the file or folder.

newPath string

The new name of the file or folder.

Source:
Returns:

An object with this property:


  • "err": The status of the operation, one of:

    • NO_ERROR

    • ERR_UNKNOWN

    • ERR_INVALID_PARAMS

    • ERR_NOT_FOUND

    • ERR_FILE_EXISTS



Type
object | ErrorCode

<static> showOpenDialog(allowMultipleSelection, chooseDirectory, title, initialPath, fileTypes)

Displays the OS File Open dialog, allowing the user to select files or directories.

Parameters:
Name Type Description
allowMultipleSelection boolean

When true, multiple files/folders can be selected.

chooseDirectory boolean

When true, only folders can be selected. When false, only
files can be selected.

title string

Title of the open dialog.

initialPath string

Initial path to display in the dialog. Pass NULL or "" to
display the last path chosen.

fileTypes Array.<string>

The file extensions (without the dot) for the types
of files that can be selected. Ignored when chooseDirectory=true.

Source:
Returns:

An object with these properties:


  • "data": An array of the full names of the selected files.

  • "err": The status of the operation, one of

    • NO_ERROR

    • ERR_INVALID_PARAMS



Type
object | ErrorCode
Example
// Display images chosen from showOpenDialog() in <img> tags

   var cepEngine = window.cep.fs,
       $imgBttn = $('button'),
       $imgDiv = $('.results'), 
       fileTypes = ["gif", "jpg", "jpeg", "png", "bmp", "webp", "svg"],
       choices = cepEngine.showOpenDialog(true, false, 'Open References', '', fileTypes),
       images = choices.data; // The array of files selected by the user
   function openImages() {
     if (images.length) {
         for (var i = 0; i < images.length; i++) {
              var imgurl = images[i];
              $imgDiv.append("<img src='" + imgurl + "'/>");
          }
      } else {
          return false;
      }
  }
  $imgBttn.click(openImages);

<static> showOpenDialogEx(allowMultipleSelection, chooseDirectory, title, initialPath, fileTypes, friendlyFilePrefix, prompt)

Displays the OS File Open dialog, allowing the user to select files or directories.

Parameters:
Name Type Description
allowMultipleSelection boolean

When true, multiple files/folders can be selected.

chooseDirectory boolean

When true, only folders can be selected. When false, only
files can be selected.

title string

Title of the open dialog.

initialPath string

Initial path to display in the dialog. Pass NULL or "" to
display the last path chosen.

fileTypes Array.<string>

The file extensions (without the dot) for the types
of files that can be selected. Ignored when chooseDirectory=true.

friendlyFilePrefix string

String to put in front of the extensions
of files that can be selected. Ignored when chooseDirectory=true. (win only)

prompt string

String for OK button (mac only, default is "Open" on mac, "Open" or "Select Folder" on win).

Source:
Returns:

An object with these properties:

  • "data": An array of the full names of the selected files.

  • "err": The status of the operation, one of

    • NO_ERROR

    • ERR_INVALID_PARAMS



Type
object | ErrorCode
Example
// Example filetypes and prefixes
   var cepEngine = window.cep.fs,
       $imgBttn = $('button'),
       $imgDiv = $('.results'), 
     fileTypes = ["gif", "jpg", "jpeg", "png", "bmp", "webp", "svg"],
     friendlyFilePrefix = "Images (*.gif;*.jpg;*.jpeg;*.png;*.bmp;*.webp;*.svg)",
     choices = cepEngine.showOpenDialogEx(true, false, 'Open References', '', fileTypes, friendlyFilePrefix),
     images = choices.data; // The array of files selected by the user
   function openImages() {
     if (images.length) {
         for (var i = 0; i < images.length; i++) {
              var imgurl = images[i];
              $imgDiv.append("<img src='" + imgurl + "'/>");
          }
      } else {
          return false;
      }
  }
  $imgBttn.click(openImages);

<static> showSaveDialogEx(title, initialPath, fileTypes, defaultName, friendlyFilePrefix, prompt, nameFieldLabel)

Displays the OS File Save dialog, allowing the user to type in a file name.

Parameters:
Name Type Description
title string

Title of the save dialog.

initialPath string

Initial path to display in the dialog. Pass NULL or "" to
display the last path chosen.

fileTypes Array.<string>

The file extensions (without the dot) for the types
of files that can be selected.

defaultName string

String to start with for the file name.

friendlyFilePrefix string

String to put in front of the extensions of files that can be selected. (win only)

prompt string

String for Save button (mac only, default is "Save" on mac and win).

nameFieldLabel string

String displayed in front of the file name text field (mac only, "File name:" on win).

Source:
Returns:

An object with these properties:

  • "data": The file path selected to save at or "" if canceled

  • "err": The status of the operation, one of

    • NO_ERROR

    • ERR_INVALID_PARAMS



Type
object | ErrorCode
Example
// Example filetypes and prefixes
         var fileTypes = ["gif", "jpg", "jpeg", "png", "bmp", "webp", "svg"];
         var friendlyFilePrefix = "Images (*.gif;*.jpg;*.jpeg;*.png;*.bmp;*.webp;*.svg)";

<static> stat(path)

Reports whether an item is a file or folder.

Parameters:
Name Type Description
path string

The path of the file or folder.

Source:
Returns:

An object with these properties:


  • "data": An object with properties

    • isFile (boolean)

    • isDirectory (boolean)

    • mtime (modification DateTime)



  • "err": The status of the operation, one of

    • NO_ERROR

    • ERR_UNKNOWN

    • ERR_INVALID_PARAMS

    • ERR_NOT_FOUND



Type
object | ErrorCode

<static> writeFile(path, data, encoding)

Writes data to a file, replacing the file if it already exists.

Parameters:
Name Type Description
path string

The path of the file to write.

data string

The data to write to the file.

encoding string

The encoding of the contents of file, one of
UTF8 (the default) or Base64.

Source:
Returns:

An object with this property:


  • "err": The status of the operation, one of:

    • NO_ERROR

    • ERR_UNKNOWN

    • ERR_INVALID_PARAMS

    • ERR_UNSUPPORTED_ENCODING

    • ERR_CANT_WRITE

    • ERR_OUT_OF_SPACE



Type
object | ErrorCode