path
Utilities for working with file and directory paths, supporting the separator from the operating system.
Similar packages:
Package | Description |
---|---|
path | recognises the path-part separator from the operating system |
upath | recognises the
/
|
wpath | recognises the
\
|
bpath | recognises both
/
\
|
Synopsis
import prantlf.path { dirname }
home_dir := ... // '/home/prantlf' or r'C:\Users\prantlf'
dirname(home_dir) // returns '/home' or r'C:\Users'
Installation
You can install this package either from
VPM
v install prantlf.path
v install --git https://github.com/prantlf/v-path
API
The following functions are exported:
basename(path string) string
Theis method returns the last portion of a path, similar to the
POSIX basename
home_dir := ... // '/home/prantlf' or r'C:\Users\prantlf'
path.basename(home_dir) // returns 'prantlf'
dirname(path string) string
This method returns the directory name of a path, similar to the
POSIX dirname
home_dir := ... // '/home/prantlf' or r'C:\Users\prantlf'
path.dirname(home_dir) // returns '/home' or r'C:\Users'
extname(path string) string
This method returns the extension of the path, from the last occurrence of the
.
.
.
basename
// sets '/home/prantlf/info.txt' or r'C:\Users\prantlf\info.txt'
info_file := os.join_path_single(os.getwd(), 'info.txt')
// returns '.txt'
path.extname(info_file)
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.
License
Copyright (c) 2023 Ferdinand Prantl
Licensed under the MIT license.