String module

path_extension

procedure · 1 overloadSource

The extension of the last component of path, without the dot, and whether it has one.

path_extension :: (path: string) -> (extension: string, found_extension: bool)

A dot at the start of the name does not start an extension, so .hidden has none. With several dots the last one counts.

Parameters

path: string

Returns

extension: string
found_extension: bool
ExampleOpen in playground ↗
ext, found := path_extension("dir/archive.tar.gz");
assert(found && ext == "gz");

_, hidden := path_extension("dir/.hidden");
assert(!hidden);

See also