Skip to main content

Filesystem

The Lua binding is based on the C++ library boost filesystem. In contrary to the original C++ design, the Lua binding does not define an abstraction for path. Instead, path always refers to a Lua string. The join function allows concatenating paths using the platform dependent separator.

local fs = Filesystem

local script = fs.join(Kontakt.script_path, Kontakt.script_file)
assert(fs.exists(script))

API Access

The Filesystem API is defined in the global table Filesystem, i.e. all constants and functions need to be prefixed with that name. For example.

print(Filesystem.exists(Kontakt.script_path))

-- also works
kt = Kontakt
fs = Filesystem

print(fs.exists(kt.script_path))

Iterators

directory

directory(path: string) -> iterator

Example: lists paths in directory

for _, p in Filesystem.directory(path) do
    print(p)
end

recursive_directory

recursive_directory(path: string) -> iterator

Example: lists paths in directory and all sub-directories

for _, p in Filesystem.recursive_directory(path) do
    print(p)
end

Path Functions

empty

empty(path: string) -> boolean

extension

extension(path: string) -> string

filename

filename(path: string) -> string

has_parent_path

has_parent_path(path: string) -> boolean

has_relative_path

has_relative_path(path: string) -> boolean

has_root_directory

has_root_directory(path: string) -> boolean

has_extension

has_extension(path: string) -> boolean

has_filename

has_filename(path: string) -> boolean

has_root_name

has_root_name(path: string) -> boolean

is_dot_dot

is_dot_dot(path: string) -> boolean

is_dot

is_dot(path: string) -> boolean

join

join(paths ... : string) -> string

has_stem

has_stem(path: string) -> boolean

is_absolute

is_absolute(path: string) -> boolean

relative_path

relative_path(path: string) -> string

has_root_path

has_root_path(path: string) -> boolean

root_name

root_name(path: string) -> string

root_directory

root_directory(path: string) -> string

is_relative

is_relative(path: string) -> boolean

parent_path

parent_path(path: string) -> string

root_path

root_path(path: string) -> string

replace_extension

replace_extension(path: string, extension: string) -> string

preferred

preferred(path: string) -> string

stem

stem(path: string) -> string