Meet Virtel Maple 3.4.x! New UI, Custom colors, PQCrypto and Fixes.

Download

Files

Managing File System Operations

Objective: Read, write, and manage files and directories.

Steps:
  • Write to a file:
    fls write "$/files/data.txt" "Hello World";
    • "$/files/data.txt" is the file path.
    • "Hello World" is the content to write.
  • Read from a file:
    fls read "$/files/data.txt" fileContent; csl write fileContent;
    • "$/files/data.txt" is the file path.
    • "fileContent" is the variable to store the content.
  • Check if a file exists:
    fls xst "$/files/data.txt" exists; csl write exists;

Practical Example

Objective: Create a directory and write a file to it.

Steps:
  • Create a directory:
    fls dir "$/files/newFolder";
  • Write a file to the directory:
    fls write "$/files/newFolder/info.txt" "New file";

Tips

  • Use "$" to reference the system path.
  • Ensure directories exist before writing files.
  • Delete unnecessary files to free up space.

Conclusion

File commands like fls write, fls read, and fls dir enable interaction with the file system, ensuring data storage and management.

Commands

fls read

Reads the content of a file at a specified path and stores it in a new variable.

fls read (path) (newVarName)
  • path: The path to the file (replaces "$" with the system path) (type: VAR).
  • newVarName: The name of the new variable to store the content (type: VAR).
fls read "$/files/data.txt" fileContent; csl write fileContent;

This example reads the content of "/system/files/data.txt" and prints it.

fls write

Writes a value to a file at a specified path, creating directories if they don’t exist.

fls write (path) (value)
  • path: The path to the file (replaces "$" with the system path) (type: VAR).
  • value: The value to write (type: VAR).
fls write "$/files/data.txt" "Hello World";

This example writes "Hello World" to "/system/files/data.txt".

fls del

Deletes a file or directory recursively at a specified path.

fls del (path)
  • path: The path to the file or directory (replaces "$" with the system path) (type: VAR).
fls del "$/files/oldData.txt";

This example deletes the file "/system/files/oldData.txt".

fls dir

Creates a new directory at a specified path.

fls dir (path)
  • path: The path to the new directory (replaces "$" with the system path) (type: VAR).
fls dir "$/files/newFolder";

This example creates a new directory "/system/files/newFolder".

fls list

Gets a list of files in a directory and stores it in a new list variable.

fls list (path) (newListName)
  • path: The path to the directory (replaces "$" with the system path) (type: VAR).
  • newListName: The name of the new list to store the file names (type: LIST).
fls list "$/files" fileList; lst get fileList "0" firstFile; csl write firstFile;

This example lists files in "/system/files" and prints the first file name.

fls xst

Checks if a file or directory exists at a specified path and stores the result ("true" or "false") in a new variable.

fls xst (path) (newVarName)
  • path: The path to check (replaces "$" with the system path) (type: VAR).
  • newVarName: The name of the new variable to store the result (type: VAR).
fls xst "$/files/data.txt" exists; csl write exists;

This example checks if "/system/files/data.txt" exists and prints "true" or "false".

zip archive

Archives a folder into a ZIP file.

zip archive (folderPath) (newZipFilePath)
  • folderPath: The path to the folder to archive (type: VAR).
  • newZipFilePath: The path to the new ZIP file (type: VAR).
zip archive "$/files/myfolder" "$/files/archive.zip";

This example archives the folder "/system/files/myfolder" into "/system/files/archive.zip".

zip extract

Extracts a ZIP file into a specified folder.

zip extract (zipFilePath) (folderPath)
  • zipFilePath: The path to the ZIP file (type: VAR).
  • folderPath: The path to the folder where the archive will be extracted (type: VAR).
zip extract "$/files/archive.zip" "$/files/extracted";

This example extracts "/system/files/archive.zip" into "/system/files/extracted".