Files
Managing File System Operations
Objective: Read, write, and manage files and directories.
- 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.
- 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
Reads the content of a file at a specified path and stores it in a new variable.
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).
This example reads the content of "/system/files/data.txt" and prints it.
Writes a value to a file at a specified path, creating directories if they don’t exist.
path
: The path to the file (replaces "$" with the system path) (type: VAR).value
: The value to write (type: VAR).
This example writes "Hello World" to "/system/files/data.txt".
Deletes a file or directory recursively at a specified path.
path
: The path to the file or directory (replaces "$" with the system path) (type: VAR).
This example deletes the file "/system/files/oldData.txt".
Creates a new directory at a specified path.
path
: The path to the new directory (replaces "$" with the system path) (type: VAR).
This example creates a new directory "/system/files/newFolder".
Gets a list of files in a directory and stores it in a new list variable.
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).
This example lists files in "/system/files" and prints the first file name.
Checks if a file or directory exists at a specified path and stores the result ("true" or "false") in a new variable.
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).
This example checks if "/system/files/data.txt" exists and prints "true" or "false".
Archives a folder into a ZIP file.
folderPath
: The path to the folder to archive (type: VAR).newZipFilePath
: The path to the new ZIP file (type: VAR).
This example archives the folder "/system/files/myfolder" into "/system/files/archive.zip".
Extracts a ZIP file into a specified folder.
zipFilePath
: The path to the ZIP file (type: VAR).folderPath
: The path to the folder where the archive will be extracted (type: VAR).
This example extracts "/system/files/archive.zip" into "/system/files/extracted".