./redteamer

Functions

Filesystem Functions

Functions for working with the filesystem.


File Path Manipulation

File path manipulation functions help manage and manipulate filesystem paths.

abs_path

The fs::abs_path function transforms a given filesystem path into an absolute path.

fs::abs_path("foo/bar/baz.txt")
# Example Result: "/home/user/foo/bar/baz.txt"

dir_name

The fs::dir_name function trims off the last portion of a filesystem path.

fs::dir_name("foo/bar/baz.txt")
# Result: "foo/bar"

path_expand

The fs::path_expand function processes a filesystem path starting with ~ and replaces it with the current user's home directory path.

fs::path_expand("~/.ssh/id_rsa")
# Example Result: "/home/user/.ssh/id_rsa"

base_name

The fs::base_name function trims off all but the last segment of a filesystem path.

fs::base_name("foo/bar/baz.txt")
# Result: "baz.txt"

File Reading and Writing

File reading and writing functions assist with reading from and writing to files.

file

The fs::file function reads the contents of a file at a specified path and returns them as a string.

fs::file("${path.module_dir}/hello.txt")
# Example Result: "Hello World"

templatefile

The templatefile function reads a file at a given path and renders its content as a template using a supplied set of template variables.

templatefile("${path.module_dir}/config.tpl", {username = "admin", password = "secret"})
# Example Result: "username: admin\npassword: secret"

File Existence and Enumeration

File existence and enumeration functions allow for checking file existence and enumerating files based on specific patterns.

file_exists

The fs::file_exists function checks if a file exists at a specified path and returns a boolean value.

fs::file_exists("${path.module_dir}/hello.txt")
# Result: true

fileset

The fs::fileset function generates a set of regular file names based on a given path and pattern.

fs::fileset(path.module_dir, "files/*.txt")
# Example Result: ["files/hello.txt", "files/world.txt"]

exec_exists

The fs::exec_exists function checks if an executable exists in the system path and returns a boolean value.

fs::exec_exists("git")
# Result: true
Previous
Encoding Functions