package core:path/filepath
Overview
The path/filepath package uses 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 path package
Index
Types (3)
Constants (4)
Variables (0)
This section is empty.
Procedure Groups (0)
This section is empty.
Types
Relative_Error ¶
Relative_Error :: enum int { None, Cannot_Relate, }
Related Procedures With Returns
Walk_Proc ¶
Walk_Proc :: proc(info: os.File_Info, in_err: os.Error, user_data: rawptr) -> (err: os.Error, skip_dir: bool)
Walk_Proc is the type of the procedure called for each file or directory visited by 'walk' The 'path' parameter contains the parameter to walk as a prefix (this is the same as info.fullpath except on 'root') The 'info' parameter is the os.File_Info for the named path
If there was a problem walking to the file or directory named by path, the incoming error will describe the problem and the procedure can decide how to handle that error (and walk will not descend into that directory) In the case of an error, the info argument will be 0 If an error is returned, processing stops The sole exception is if 'skip_dir' is returned as true:
when 'skip_dir' is invoked on a directory. 'walk' skips directory contents when 'skip_dir' is invoked on a non-directory. 'walk' skips the remaining files in the containing directory
Related Procedures With Parameters
Constants
LIST_SEPARATOR ¶
LIST_SEPARATOR :: ';'
SEPARATOR ¶
SEPARATOR :: '\\'
SEPARATOR_CHARS ¶
SEPARATOR_CHARS :: `/\`
SEPARATOR_STRING ¶
SEPARATOR_STRING :: `\`
Variables
This section is empty.
Procedures
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) #optional_ok {…}
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 :: proc(path: string, allocator := context.allocator) -> string {…}
Returns all but the last element path, usually the path's directory. Once the final element has been removed,
dir
calls clean
on the path and trailing separators are removed. If the path consists purely of separators,
then "."
is returned.
ext ¶
Gets the file extension from a path, including the dot.
The file extension is such that stem(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.
from_slash ¶
from_slash :: proc(path: string, allocator := context.allocator) -> (new_path: string, new_allocation: bool) {…}
Returns the result of replacing each forward slash /
character in the path with the separate OS specific character.
glob ¶
glob :: proc(pattern: string, allocator := context.allocator) -> (matches: []string, err: Match_Error) {…}
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_separator ¶
is_separator checks whether the byte is a valid separator character
join ¶
join :: proc(elems: []string, allocator := context.allocator) -> string {…}
join_non_empty ¶
join_non_empty :: proc(elems: []string, allocator := context.allocator) -> string {…}
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 :: proc(pattern, name: string) -> (matched: bool, err: Match_Error) {…}
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
NOTE(bill): This is effectively the shell pattern matching system found
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.
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).
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 ¶
Splits path immediate following the last separator; separating the path into a directory and file.
If no separator is found, dir
will be empty and path
set to path
.
split_list ¶
split_list :: proc(path: string, allocator := context.allocator) -> (list: []string, err: runtime.Allocator_Error) #optional_ok {…}
Splits the PATH-like path
string, returning an array of its separated components (delete after use).
For Windows the separator is ;
, for Unix it's :
.
An empty string returns nil. A non-empty string with no separators returns a 1-element array.
Any empty components will be included, e.g. a::b
will return a 3-element array, as will ::
.
Separators within pairs of double-quotes will be ignored and stripped, e.g. "a:b"c:d
will return []{a:bc
, d
}.
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 there is no stem. e.g: '.gitignore'. Returns an empty string if there's a trailing path separator.
to_slash ¶
to_slash :: proc(path: string, allocator := context.allocator) -> (new_path: string, new_allocation: bool) {…}
Returns the result of replacing each OS specific separator with a forward slash /
character.
volume_name ¶
Returns leading volume name.
e.g. "C:\foo\bar\baz" will return "C:" on Windows. Everything else will be "".
volume_name_len ¶
Returns the length of the volume name in bytes.
walk ¶
walk walks the file tree rooted at 'root', calling 'walk_proc' for each file or directory in the tree, including 'root' All errors that happen visiting files and directories are filtered by walk_proc The files are walked in lexical order to make the output deterministic NOTE: Walking large directories can be inefficient due to the lexical sort NOTE: walk does not follow symbolic links NOTE: os.File_Info uses the 'context.temp_allocator' to allocate, and will delete when it is done
Procedure Groups
This section is empty.
Source Files
- match.odin
- path.odin
- walk.odin
- (hidden platform specific files)
Generation Information
Generated with odin version dev-2024-11 (vendor "odin") Windows_amd64 @ 2024-11-20 21:11:50.792979400 +0000 UTC