2019-11-01 19:29:51 +03:00
|
|
|
module filepath
|
|
|
|
|
2019-12-20 00:29:37 +03:00
|
|
|
import (
|
2019-11-01 19:29:51 +03:00
|
|
|
os
|
|
|
|
)
|
|
|
|
// return the extension in the file `path`
|
2019-12-20 00:29:37 +03:00
|
|
|
|
|
|
|
|
2019-11-01 19:29:51 +03:00
|
|
|
pub fn ext(path string) string {
|
|
|
|
pos := path.last_index_byte(`.`)
|
|
|
|
if pos != -1 {
|
|
|
|
return path[pos..]
|
|
|
|
}
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns true if `path` is absolute
|
|
|
|
pub fn is_abs(path string) bool {
|
|
|
|
$if windows {
|
|
|
|
return path[0] == `/` || // incase we're in MingGW bash
|
2019-12-20 00:29:37 +03:00
|
|
|
(path[0].is_letter() && path[1] == `:`)
|
2019-11-01 19:29:51 +03:00
|
|
|
}
|
|
|
|
return path[0] == `/`
|
|
|
|
}
|
|
|
|
|
2019-12-20 00:29:37 +03:00
|
|
|
// pass directories as parameters, returns path as string
|
2019-11-01 19:29:51 +03:00
|
|
|
// TODO use []string.join once ...string becomes "[]string"
|
|
|
|
pub fn join(base string, dirs ...string) string {
|
2019-11-17 06:45:20 +03:00
|
|
|
mut result := []string
|
|
|
|
result << base.trim_right('\\/')
|
2019-12-20 00:29:37 +03:00
|
|
|
for d in dirs {
|
|
|
|
result << d
|
|
|
|
}
|
|
|
|
return result.join(os.path_separator)
|
2019-11-01 19:29:51 +03:00
|
|
|
}
|
2019-12-20 00:29:37 +03:00
|
|
|
|