Introduction
The built-in @weintek/filesystem
module provides facilities for performing operations on file systems, such as creating directories and deleting files and directories on an inserted USB drive or SD card. This post covers how to manipulate files and directories using the JS object.
Warning
JS objects provide powerful customization features, but using them incorrectly can result in system error or performance degradation. Please use JS objects carefully.
Software Version
The JS Object is exclusive to cMT-X series HMIs.
EasyBuilder Pro 6.09.01+
Related Tutorials
How to transfer device data using the JS object
Video - Introduction to Weintek’s JS Object (JavaScript)
Video - How to designate a USB drive as USB1 or USB2
JS Action/Object SDK Documentation
Instructions
Examples
Create a directory:
This method creates a directory on a USB drive or SD card inserted in an HMI.
const fs = await import('@weintek/filesystem');
const disk = 'USB1';
const path = 'test';
fs.createDirectory(disk, 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 path of the directory to be created. |
Note: the code throughout this post needs to be entered within the JS object’s “Source code” tab:
After the source code has been entered into the JS object, place the object within your project:
Result:
Delete a directory and all of its subdirectories/files:
This method deletes the directory identified by disk
and path
and all its subdirectories/files.
const fs = await import('@weintek/filesystem');
const disk = 'USB1';
const path = 'test';
fs.removeAll(disk, 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 directory path. |
After the source code has been entered into the JS object, place the object within your project:
Result:
Before
After
Methods
Creating a directory
This method creates a directory on a USB drive or SD card inserted in an HMI.
(static) createDirectory(disk, 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 path of the directory to be created. |
Delete a file or empty directory
This method deletes the file or empty directory identified by disk
and path
.
(static) remove(disk, 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. |
Delete a directory and all of its subdirectories/files
This method deletes the directory identified by disk
and path
and all its subdirectories/files.
(static) removeAll(disk, 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 directory path. |