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

Types

Match_Error ¶

Match_Error :: enum int {
	None, 
	Syntax_Error, 
}

Relative_Error ¶

Relative_Error :: enum int {
	None, 
	Cannot_Relate, 
}

Walk_Proc ¶

Walk_Proc :: proc "odin" (info: os.File_Info, in_err: os.Errno, user_data: rawptr) -> (err: os.Errno, 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

Constants

LIST_SEPARATOR ¶

LIST_SEPARATOR :: ';'

SEPARATOR ¶

SEPARATOR :: '\\'

SEPARATOR_CHARS ¶

SEPARATOR_CHARS :: `/\`

SEPARATOR_STRING ¶

SEPARATOR_STRING :: `\`

Variables

This section is empty.

Procedures

abs ¶

abs :: proc "odin" (path: string, allocator := context.allocator) -> (new_path: string, new_allocation: bool) {…}

base ¶

base :: proc "odin" (path: string) -> string {…}
 

Gets the file name and extension from a path.

i.e:
  '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 "odin" (path: string, allocator := context.allocator) -> string {…}

dir ¶

dir :: proc "odin" (path: string, allocator := context.allocator) -> string {…}

ext ¶

ext :: proc "odin" (path: string) -> string {…}
 

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`.

i.e:
  '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 "odin" (path: string, allocator := context.allocator) -> (new_path: string, new_allocation: bool) {…}

glob ¶

glob :: proc "odin" (pattern: string, allocator := context.allocator) -> (matches: []string, err: Match_Error) {…}

is_UNC ¶

is_UNC :: proc "odin" (path: string) -> bool {…}

is_abs ¶

is_abs :: proc "odin" (path: string) -> bool {…}

is_reserved_name ¶

is_reserved_name :: proc "odin" (path: string) -> bool {…}

is_separator ¶

is_separator :: proc "odin" (x: u8) -> bool {…}
 

is_separator checks whether the byte is a valid separator character

join ¶

join :: proc "odin" (elems: []string, allocator := context.allocator) -> string {…}

join_non_empty ¶

join_non_empty :: proc "odin" (elems: []string, allocator := context.allocator) -> string {…}

long_ext ¶

long_ext :: proc "odin" (path: string) -> string {…}
 

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.

i.e:
  '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 "odin" (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 "odin" (base_path, target_path: string, allocator := context.allocator) -> (string, Relative_Error) {…}

short_stem ¶

short_stem :: proc "odin" (path: string) -> string {…}
 

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.

i.e:
  '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 :: proc "odin" (path: string) -> (dir, file: string) {…}

split_list ¶

split_list :: proc "odin" (path: string, allocator := context.allocator) -> []string {…}
 

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 ¶

stem :: proc "odin" (path: string) -> string {…}
 

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`.

i.e:
  '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 "odin" (path: string, allocator := context.allocator) -> (new_path: string, new_allocation: bool) {…}

volume_name ¶

volume_name :: proc "odin" (path: string) -> string {…}

volume_name_len ¶

volume_name_len :: proc "odin" (str: string) -> (w: int) {…}

walk ¶

walk :: proc "odin" (root: string, walk_proc: Walk_Proc, user_data: rawptr) -> os.Errno {…}
 

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

Generation Information

Generated with odin version dev-2022-12 (vendor "odin") Windows_amd64 @ 2022-12-06 21:08:55.177553500 +0000 UTC