@weintek/filesystem

The built-in @weintek/filesystem module provides facilities for performing operations on file systems, such as create directories and delete files and directories.

Note:

  • The module is availabe when JS object/action is run on Local HMI)
Example

Create a directory and delete it later

const fs = await import('@weintek/filesystem');
const disk = 'USB1';
const path = 'test';

fs.createDirectory(disk, path);
if (fs.exists(disk, path)) {
    console.log('isDirectory =', fs.isDirectory(disk, path));
    fs.remove(disk, path);
}

Methods

(static) createDirectory(disk, path) → {Boolean}

Since:
  • EasyBuilder Pro V6.09.01

This method creates a directory.

Notes that this will fail (by returning false) if parent directory doesn't exist.

Parameters:
Name Type Description
disk String

A string specifies the target disk. Acceptable values are SD, USB1 and USB2.

path String

A string specifies path of the directory to be created.

Returns:

Returns true if the directory is successfully created, false otherwise.

Type
Boolean

(static) exists(disk, path) → {Boolean}

Since:
  • EasyBuilder Pro V6.09.01

This method tests whether or not the given path exists.

Parameters:
Name Type Description
disk String

A string specifies the target disk. Acceptable values are SD, USB1 and USB2.

path String

A string specifies the path to be tested.

Returns:

Returns true if the path exists, false otherwise.

Type
Boolean

(static) fileSize(disk, path) → {Number}

Since:
  • EasyBuilder Pro V6.09.01

This method returns file size in bytes.

Parameters:
Name Type Description
disk String

A string specifies the target disk. Acceptable values are SD, USB1 and USB2.

path String

A string specifies the file path.

Returns:

Returns file size in bytes.

Type
Number

(static) isDirectory(disk, path) → {Boolean}

Since:
  • EasyBuilder Pro V6.09.01

This method tests whether or not the given path is a directory.

Parameters:
Name Type Description
disk String

A string specifies the target disk. Acceptable values are SD, USB1 and USB2.

path String

A string specifies the path to be tested.

Returns:

Returns true if the path is a directory, false otherwise.

Type
Boolean

(static) isRegularFile(disk, path) → {Boolean}

Since:
  • EasyBuilder Pro V6.09.01

This method tests whether or not the given path is a regular file.

Parameters:
Name Type Description
disk String

A string specifies the target disk. Acceptable values are SD, USB1 and USB2.

path String

A string specifies the path to be tested.

Returns:

Returns true if the path is a regular file, false otherwise.

Type
Boolean

(static) readdir(disk, path) → {Array.String}

Since:
  • EasyBuilder Pro V6.09.01

This method returns names of the files in the directory identified by disk and path.

Parameters:
Name Type Description
disk String

A string specifies the target disk. Acceptable values are SD, USB1 and USB2.

path String

A string specifies the file path.

Returns:

Returns an array of file names (excluding '.' and '..').

Type
Array.String

(static) remove(disk, path) → {Boolean}

Since:
  • EasyBuilder Pro V6.09.01

This method deletes the file or empty directory identified by disk and path.

Parameters:
Name Type Description
disk String

A string specifies the target disk. Acceptable values are SD, USB1 and USB2.

path String

A string specifies the file path.

Returns:

Returns true if the file was deleted, false if it did not exist.

Type
Boolean

(static) removeAll(disk, path) → {Number}

Since:
  • EasyBuilder Pro V6.09.01

This method deletes the directory identified by disk and path and all its subdirectories.

Parameters:
Name Type Description
disk String

A string specifies the target disk. Acceptable values are SD, USB1 and USB2.

path String

A string specifies the directory path.

Returns:

Returns the number of files and directories that were deleted.

Type
Number