package core:path/filepath
Overview
Process paths using either forward slashes or backslashes depending on the operating system. To process paths such as URLs that depend on forward slashes regardless of the OS, use the slashpath package.
Index
Types (2)
Constants (4)
Variables (0)
This section is empty.
Procedures (28)
Procedure Groups (2)
Types
Relative_Error ¶
Relative_Error :: enum int { None, Cannot_Relate, }
Constants
LIST_SEPARATOR ¶
LIST_SEPARATOR :: ';'
SEPARATOR ¶
SEPARATOR :: '\\'
SEPARATOR_CHARS ¶
SEPARATOR_CHARS :: `/\`
SEPARATOR_STRING ¶
SEPARATOR_STRING :: `\`
Variables
This section is empty.
Procedures
abs ¶
@(require_results) abs :: proc( path: string, allocator := context.allocator, ) -> (absolute_path: string, error: os.Error) {…}
Get the absolute path to path with respect to the process's current directory.
Allocates Using Provided Allocator
base ¶
base :: os.base
Gets the file name and extension from a path.
e.g.
'path/to/name.tar.gz' -> 'name.tar.gz' 'path/to/name.txt' -> 'name.txt' 'path/to/name' -> 'name'
Returns "." if the path is an empty string.
clean ¶
clean :: proc( path: string, allocator := context.allocator, ) -> (cleaned: string, err: runtime.Allocator_Error) {…}
Returns the shortest path name equivalent to path through solely lexical processing.
It applies the folliwng rules until none of them can be applied:
- Replace multiple separators with a single one
- Remove each current directory (
.) path name element - Remove each inner parent directory (
..) path and the preceding paths - Remove
..that begin at the root of a path - All possible separators are replaced with the OS specific separator
The return path ends in a slash only if it represents the root of a directory (C:\ on Windows and / on *nix systems).
If the result of the path is an empty string, the returned path with be ".".
dir ¶
dir :: os.dir
Gets the parent directory path from a path.
e.g.
'/home/foo/bar.tar.gz' -> '/home/foo' 'path/to/name.tar.gz' -> 'path/to'
Returns "." if the path is an empty string.
ext ¶
ext :: os.ext
Gets the file extension from a path, including the dot.
The file extension is such that stem_path(path) + ext(path) = base(path).
Only the last dot is considered when splitting the file extension.
See long_ext.
e.g.
'name.tar.gz' -> '.gz' 'name.txt' -> '.txt'
Returns an empty string if there is no dot. Returns an empty string if there is a trailing path separator.
glob ¶
glob :: os.glob
glob returns the names of all files matching pattern or nil if there are no matching files The syntax of patterns is the same as "match". The pattern may describe hierarchical names such as /usr/*/bin (assuming '/' is a separator)
glob ignores file system errors
is_abs ¶
is_abs :: os.is_absolute_path
Return true if path is an absolute path as opposed to a relative one.
is_reserved_name ¶
is_reserved_name :: os.is_reserved_name
is_separator ¶
is_separator :: os.is_path_separator
Return true if c is a character used to separate paths into directory and
file hierarchies on the current system.
join ¶
join :: proc( elems: []string, allocator := context.allocator, ) -> (joined: string, err: runtime.Allocator_Error) {…}
Join all elems with the system's path separator and normalize the result.
Allocates Using Provided Allocator
For example, join_path({"/home", "foo", "bar.txt"}) will result in "/home/foo/bar.txt".
long_ext ¶
long_ext :: os.long_ext
Gets the file extension from a path, including the dot.
The long file extension is such that short_stem(path) + long_ext(path) = base(path).
The first dot is used to split off the file extension, unlike ext which uses the last dot.
e.g.
'name.tar.gz' -> '.tar.gz' 'name.txt' -> '.txt'
Returns an empty string if there is no dot. Returns an empty string if there is a trailing path separator.
match ¶
match :: os.match
match states whether "name" matches the shell pattern
Pattern syntax is:
pattern:
{term}
term:
'*' matches any sequence of non-/ characters
'?' matches any single non-/ character
'[' ['^'] { character-range } ']'
character classification (cannot be empty)
c matches character c (c != '*', '?', '\\', '[')
'\\' c matches character c
character-range
c matches character c (c != '\\', '-', ']')
'\\' c matches character c
lo '-' hi matches character c for lo <= c <= hi
match requires that the pattern matches the entirety of the name, not just a substring.
The only possible error returned is .Syntax_Error or an allocation error.
NOTE(bill): This is effectively the shell pattern matching system found
read_all_directory ¶
read_all_directory :: os.read_all_directory
Reads the file f (assuming it is a directory) and returns all of the unsorted directory entries.
read_all_directory_by_path ¶
read_all_directory_by_path :: os.read_all_directory_by_path
Reads the named directory by path (assuming it is a directory) and returns all of the unsorted directory entries.
read_directory ¶
read_directory :: os.read_directory
Reads the file f (assuming it is a directory) and returns the unsorted directory entries.
This returns up to n entries OR all of them if n <= 0.
read_directory_by_path ¶
read_directory_by_path :: os.read_directory_by_path
Reads the named directory by path (assuming it is a directory) and returns the unsorted directory entries.
This returns up to n entries OR all of them if n <= 0.
rel ¶
rel :: proc( base_path, target_path: string, allocator := context.allocator, ) -> (string, Relative_Error) {…}
Returns a relative path that is lexically equivalent to the target_path when joined with the base_path with an OS specific separator.
e.g. join(base_path, rel(base_path, target_path)) is equivalent to target_path
On failure, the Relative_Error will be state it cannot compute the necessary relative path.
replace_separators ¶
replace_separators :: proc( path: string, new_sep: rune, allocator := context.allocator, ) -> (new_path: string, err: os.Error) {…}
Returns the result of replacing each path separator character in the path
with the specific character new_sep.
Allocates Using Provided Allocator
short_stem ¶
short_stem :: os.short_stem
Gets the name of a file from a path.
The short stem is such that short_stem(path) + long_ext(path) = base(path),
where long_ext is the extension returned by split_filename_all.
The first dot is used to split off the file extension, unlike stem which uses the last dot.
e.g.
'name.tar.gz' -> 'name' 'name.txt' -> 'name'
Returns an empty string if there is no stem. e.g: '.gitignore'. Returns an empty string if there's a trailing path separator.
split ¶
split :: os.split_path
Split a path into a directory hierarchy and a filename.
For example, split_path("/home/foo/bar.tar.gz") will return "/home/foo" and "bar.tar.gz".
split_list ¶
split_list :: os.split_path_list
Split a string that is separated by a system-specific separator, typically used for environment variables specifying multiple directories.
Allocates Using Provided Allocator
For example, there is the "PATH" environment variable on POSIX systems which this procedure can split into separate entries.
stem ¶
stem :: os.stem
Gets the name of a file from a path.
The stem of a file is such that stem(path) + ext(path) = base(path).
Only the last dot is considered when splitting the file extension.
See short_stem.
e.g.
'name.tar.gz' -> 'name.tar' 'name.txt' -> 'name'
Returns an empty string if the path is empty Returns an empty string if there is no stem. e.g: '.gitignore'. Returns an empty string if there's a trailing path separator.
volume_name ¶
volume_name :: os.volume_name
Returns leading volume name.
e.g.
"C:\foo\bar\baz" will return "C:" on Windows. Everything else will be "".
walker_destroy ¶
walker_destroy :: os.walker_destroy
walker_error ¶
walker_error :: os.walker_error
Returns the last error that occurred during the walker's operations.
Can be called while iterating, or only at the end to check if anything failed.
walker_skip_dir ¶
walker_skip_dir :: os.walker_skip_dir
Marks the current directory to be skipped (not entered into).
walker_walk ¶
walker_walk :: os.walker_walk
Returns the next file info in the iterator, files are iterated in breadth-first order.
If an error occurred opening a directory, you may get zero'd info struct and
walker_error will return the error.
Example:
package main
import "core:fmt"
import "core:strings"
import "core:os"
main :: proc() {
w := os.walker_create("core")
defer os.walker_destroy(&w)
for info in os.walker_walk(&w) {
// Optionally break on the first error:
// _ = walker_error(&w) or_break
// Or, handle error as we go:
if path, err := os.walker_error(&w); err != nil {
fmt.eprintfln("failed walking %s: %s", path, err)
continue
}
// Or, do not handle errors during iteration, and just check the error at the end.
// Skip a directory:
if strings.has_suffix(info.fullpath, ".git") {
os.walker_skip_dir(&w)
continue
}
fmt.printfln("%#v", info)
}
// Handle error if one happened during iteration at the end:
if path, err := os.walker_error(&w); err != nil {
fmt.eprintfln("failed walking %s: %v", path, err)
}
}
Procedure Groups
walker_create ¶
walker_create :: proc{ os.walker_create_path, os.walker_create_file, }
Creates a walker, either using a path or a file pointer to a directory the walker will start at.
For an example on how to use the walker, see walker_walk.
walker_init ¶
walker_init :: proc{ os.walker_init_path, os.walker_init_file, }
Initializes a walker, either using a path or a file pointer to a directory the walker will start at.
You are allowed to repeatedly call this to reuse it for later walks.
For an example on how to use the walker, see walker_walk.
Source Files
- match.odin
- path.odin
- walk.odin
- (hidden platform specific files)
Generation Information
Generated with odin version dev-2026-10 (vendor "odin") Windows_amd64 @ 2026-10-12 23:46:18.383355400 +0000 UTC