Contact Us

CATEGORIES

Whoops…Nothing found

Try other keywords in your search

Filesystem

 1 Minute

 0 Likes

 17 Views

This document describes the filesystem-related commands used in the provided Lua code snippets within the Control environment.


Overview

The PIXERA API exposes filesystem functionality via:

pixc.getRoot().Utils.Filesystem

All filesystem operations must be accessed through this path.


Common Workflow Pattern

Both scripts follow a consistent pattern when working with files or folders:

  1. Retrieve a path from properties
  2. Validate the input
  3. Check existence
  4. Validate type (file or directory)
  5. Perform filesystem operation
  6. Log output

Helper Usage

self.helper:getProperty(propertyName)

Retrieves a property value defined in the action.

  • Parameters:
    • propertyName (string): Name of the property (e.g., "Folder", "File")
  • Returns: string (path)

Read more: Property Builder 


Filesystem Commands

1. exists(path)

Checks whether a given path exists.

 
pixc.getRoot().Utils.Filesystem.exists(path)
  • Returns: boolean

2. isDir(path)

Checks whether the path is a directory.

 
pixc.getRoot().Utils.Filesystem.isDir(path)
  • Returns: boolean

3. isFile(path)

Checks whether the path is a file.

 
pixc.getRoot().Utils.Filesystem.isFile(path)
  • Returns: boolean

4. ls(path)

Lists the contents of a directory.

 
pixc.getRoot().Utils.Filesystem.ls(path)
  • Returns: table

5. list(path)

Alias for ls.

 
pixc.getRoot().Utils.Filesystem.list(path)
  • Returns: table

6. cat(path)

Reads the contents of a file.

 
pixc.getRoot().Utils.Filesystem.cat(path)
  • Returns: string or table

7. readAllText(path)

Alias for cat.

 
pixc.getRoot().Utils.Filesystem.readAllText(path)
  • Returns: string or table

8. rm(path)

Deletes a file or an empty directory.

 
pixc.getRoot().Utils.Filesystem.rm(path)
  • Returns: boolean (implementation dependent)
  • Notes:
    • Directory must be empty

9. remove(path)

Alias for rm.

 
pixc.getRoot().Utils.Filesystem.remove(path)

10. writeAllText(path, content)

Writes text content to a file.

 
pixc.getRoot().Utils.Filesystem.writeAllText(path, content)
  • Parameters:
    • path (string)
    • content (string)
  • Notes:
    • Overwrites existing file
    • File will not be attached automatically in PIXERA

11. mkdir(path)

Creates a new directory.

 
pixc.getRoot().Utils.Filesystem.mkdir(path)
  • Returns: boolean (implementation dependent)

Example Code

This is a code snippet used to get a file path from the properties of a Module, open the selected file, and read its content.

-- as of now with 26.2 inter 43 Options Actions are not supported with type File and Folder,
-- therefore only getProperties can be used.
if self.helper == nil then
	require "pixcHelper"
	self.helper = createPixcHelper(pixc,self())
end

-- load path as sting 
local filePath = self.helper:getProperty("File")

-- check if there is something selected
if filePath == nil or filePath == "" then
	pixc.log(currentActionFullName .. " No file selected in Properties")
	return -- leave ation if nothing selected
end

-- check if it exists
if not pixc.getRoot().Utils.Filesystem.exists(filePath) then
	pixc.log(currentActionFullName .. " Selected File path does not exist")
	return
end

-- check if it is a file
if not pixc.getRoot().Utils.Filesystem.isFile(filePath) then
	pixc.log(currentActionFullName .. " Selected File path is not a File ".. filePath)
	return
end

-- this needs to use pixc.getRoot() in order to use the Filesystem commands
-- cat is to return the content of a file
local fileContent = pixc.getRoot().Utils.Filesystem.cat(filePath)

-- logdump is used to pretty print the returned table.
pixc.log(self.helper.dump(fileContent))

You can view this example directly in Control, in the PropertiesExample module


PIXERA 26.2 Inter 43  | 25. March 2026 | J.B.

Was this article helpful?