Skip to main content

Computer.Filesystem

Allows you to create and manage an in-memory directory and file structure similar to a UNIX filesystem.
Supports file creation, deletion, renaming, reading/writing, path resolution, and optional encryption.


Functions


getRawContents

Filesystem:getRawContents()

Gets the raw contents table of the filesystem.

Returns:

  • [ table ] The directory tree.

setCurrentPath

Filesystem:setCurrentPath(path)

Sets the current working directory.

Parameters:

  • path [ string ] The new path.

getCurrentPath

Filesystem:getCurrentPath()

Gets the current working directory.

Returns:

  • [ string ] The current path.

resetCurrentPath

Filesystem:resetCurrentPath()

Resets the working directory to /.


list

Filesystem:list( path )

Lists directories and files within a folder.

Parameters:

  • path [ string ] The directory to inspect.

Returns:

  • [ table<string, "directory"|"file"> ] A list of entries in alphabetical order.

readFile

Filesystem:readFile( path )

Reads the contents of a file.

Parameters:

  • path [string ] The file to read.

Returns:

  • [ string ] File contents.

createFile

Filesystem:createFile( path, content )

Creates a new file with encoded content.

Parameters:

  • path [ string ] Destination path.
  • content [ string ] File contents.

createDirectory

Filesystem:createDirectory( path )

Creates a new directory at the given path.

Parameters:

  • path [ string ] The path to create the directory

delete

Filesystem:delete( path )

Deletes a file or directory.

Parameters:

  • path [ string ] The file or directory to delete

rename

'Filesystem:rename(oldPath, newPath)'

Renames or moves a file/directory.

Parameters:

  • oldPath [ string ] The old path.
  • newPath [ string ] The new path.

exists

Filesystem:exists( path )

Checks whether a path exists.

Parameters:

  • path [ string ] The path to check

Returns:

  • [ boolean ] Wether the file/directory exists or not

isDirectory

Filesystem:isDirectory( path )

Checks if a path refers to a directory.

Parameters:

  • path [ string ] The path to check

Returns:

  • [ boolean ] If it is a directory or not.

isFile

Filesystem:isFile( path )

Checks if a path refers to a file.

Parameters:

  • path [ string ] The path to check

Returns:

  • [ boolean ] If its a file or not.

writeToFile

Filesystem:writeToFile( path, data, createIfNotExists )

Writes data into a file. Automatically creates missing directories and the file unless disabled.

Parameters:

  • path [ string ] The path to write the file to.
  • data [ string ] The data to write to that file.
  • createIfNotExists [ boolean? ] Create the file if it doesn't exist. Defaults to true

resolve

Filesystem:resolve( path )

Resolves a relative path into an absolute path. Note that this depends on the current path!

Parameters:

  • path [ string ] The path to resolve.

Returns:

  • [ string ] The normalized /path/to/file form.

enableEncryption

This will BREAK the computer!

Due to the team wanting this update to be finished ASAP and that i (VeraDev) wasen't bothered enough to fix this, toggling encryption via this will NOT notify the computer causing unexpected behaviour!

However hopefully in the Post-V3 update, we can fix this. (This is not a promise however)

Filesystem:enableEncryption( password )
Passwords should be kept safe!

If you need to use this function where the user can access it, PLEASE ask them to retype their password twice as theres no recovery option if you forget your password!

Encrypts all filesystem contents using the provided password. You do not have to call Filesystem:enterEncryptionPassword if you are encrypting the filesystem.

Parameters:

  • password [ string ] The password to encrypt the comptuer with

disableEncryption

This will BREAK the computer!

Due to the team wanting this update to be finished ASAP and that i (VeraDev) wasen't bothered enough to fix this, toggling encryption via this will NOT notify the computer causing unexpected behaviour!

However hopefully in the Post-V3 update, we can fix this. (This is not a promise however)

Filesystem:disableEncryption()

Decrypts all contents and disables encryption.


enterEncryptionPassword

Filesystem:enterEncryptionPassword( password )

Tests if a given password can decrypt existing encrypted contents. Required for reading/writing to the filesystem

Parameters:

  • password [ string ] The password to try entering.

Returns:

  • [ boolean ] true if valid, otherwise false (Note that the computer automaticly decrypts itself if true)