path
The path module works with paths as text: it never accesses the disk. It is written in Koji: std/path.kj. To see what exists on the disk, use file.exists and file.list.
On Windows, \ separates the parts of a path as / does, and a path that starts with a drive (C:\) or a separator is absolute; join puts / between its parts, which Windows reads as well.
Functions
join(base: string, part: string) -> string
basefollowed bypart, with a separator between them:join('src', 'main.kj')is'src/main.kj'. Ifpartis absolute, it replacesbase:join('/usr', '/etc')is'/etc'.parent(path: string) -> Option[string]
The directory that containspath:parent('src/main.kj')isSome('src'), andparent('main.kj')isSome('.'). The root ('/') has no parent.name(path: string) -> Option[string]
The last part ofpath:name('src/main.kj')isSome('main.kj').stem(path: string) -> Option[string]
The name without its extension:stem('src/main.kj')isSome('main').extension(path: string) -> Option[string]
The extension, without the dot:extension('main.kj')isSome('kj'), andextension('Makefile')isNone.isAbsolute(path: string) -> boolean
Whetherpathstarts at the root ('/tmp'), rather than at the current directory ('src').
Example
import path
immut source = 'src/main.kj'
match (path.stem(source)) {
Some(stem) => print(path.join('build', `${stem}.c`)) // build/main.c
None => print('no file name')
}