path Module
The path module provides functions for working with file paths.
Functions
Join(parts...)
Joins any number of path elements into a single path.
Parameters: - parts...: The path elements to join.
Returns: - (string, error): The joined path.
Example:
| Join Example | |
|---|---|
Dir(path)
Returns the directory portion of a path.
Parameters: - path: The file path.
Returns: - (string, error): The directory portion.
Example:
| Dir Example | |
|---|---|
Base(path)
Returns the last element of a path.
Parameters: - path: The file path.
Returns: - (string, error): The last element.
Example:
| Base Example | |
|---|---|
Ext(path)
Returns the file extension of a path.
Parameters: - path: The file path.
Returns: - (string, error): The file extension.
Example:
| Ext Example | |
|---|---|
Abs(path)
Returns an absolute representation of a path.
Parameters: - path: The file path.
Returns: - (string, error): The absolute path.
Example:
Clean(path)
Returns the shortest path name equivalent to path by purely lexical processing.
Parameters: - path: The file path.
Returns: - (string, error): The cleaned path.
Example:
| Clean Example | |
|---|---|
IsAbs(path)
Reports whether a path is absolute.
Parameters: - path: The file path.
Returns: - (boolean, error): true if absolute, else false.
Example:
| IsAbs Example | |
|---|---|
Split(path)
Splits a path immediately following the final separator, returning directory and file name.
Parameters: - path: The file path.
Returns: - (string, string, error): (dir, file).
Example:
| Split Example | |
|---|---|
Rel(base, target)
Returns a relative path that is lexically equivalent to target when joined to base.
Parameters: - base: Base path. - target: Target path.
Returns: - (string, error): The relative path.
Example:
| Rel Example | |
|---|---|
ToSlash(path)
Replaces OS-specific separators with /.
Parameters: - path: Input path.
Returns: - (string, error)
Example:
| ToSlash Example | |
|---|---|
FromSlash(path)
Replaces / with OS-specific separators.
Parameters: - path: Input path.
Returns: - (string, error)
Example:
| FromSlash Example | |
|---|---|
Match(pattern, name)
Reports whether name matches the shell file name pattern.
Parameters: - pattern: Glob-style pattern (e.g. *.txt). - name: Name to match.
Returns: - (boolean, error)
Example:
| Match Example | |
|---|---|
Glob(pattern)
Returns the names of all files matching pattern, or an empty array if none.
Parameters: - pattern: Glob pattern.
Returns: - (array, error): Array of matching paths.
Example:
| Glob Example | |
|---|---|
SplitList(pathList)
Splits a list of paths joined by the OS-specific ListSeparator (: on Unix, ; on Windows).
Parameters: - pathList (string): Path list string (e.g., from PATH environment variable)
Returns: - (array, error): Array of individual path strings.
Example:
VolumeName(path)
Returns the leading volume name. On Windows, returns the drive letter (e.g., "C:"). On Unix systems, returns an empty string.
Parameters: - path (string): File path
Returns: - (string, error): Volume name or empty string.
Example:
See Also
- OS Module - Operating system interactions
- String Module - String manipulation functions