filepath

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2025 License: BSD-3-Clause Imports: 2 Imported by: 9

README

filepath GoDoc

Usage

local filepath = require("filepath")

-- filepath.ext()
local result = filepath.ext("/var/tmp/file.name")
if not(result == ".name") then error("ext") end

-- filepath.basename()
local result = filepath.basename("/var/tmp/file.name")
if not(result == "file.name") then error("basename") end

-- filepath.dir()
local result = filepath.dir("/var/tmp/file.name")
if not(result == "/var/tmp") then error("dir") end

-- filepath.join()
local result = filepath.join("/var", "tmp", "file.name")
if not(result == "/var/tmp/file.name") then error("join") end

-- filepath.glob()
local result = filepath.glob("/var/*/*.name")
if not(result[1] == "/var/tmp/file.name") then error("glob") end

Documentation

Overview

Package filepath implements golang filepath functionality for lua.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs added in v0.5.0

func Abs(L *lua.LState) int

Abs returns an absolute representation of path.

func Basename

func Basename(L *lua.LState) int

Basename lua filepath.basename(path) returns the last element of path

Example

filepath.basename(string)

state := lua.NewState()
Preload(state)
source := `
    local filepath = require("filepath")
    local result = filepath.basename("/var/tmp/file.name")
    print(result)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

file.name

func Clean added in v0.5.0

func Clean(L *lua.LState) int

Clean returns the shortest path name equivalent to path

func Dir

func Dir(L *lua.LState) int

Dir lua filepath.dir(path) returns all but the last element of path, typically the path's directory

Example

filepath.basename(string)

state := lua.NewState()
Preload(state)
source := `
    local filepath = require("filepath")
    local result = filepath.dir("/var/tmp/file.name")
    print(result)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

/var/tmp
func EvalSymlinks(L *lua.LState) int

EvalSymlinks returns the path name after the evaluation of any symbolic link.

func Ext

func Ext(L *lua.LState) int

Ext lua filepath.ext(path) returns the file name extension used by path.

Example

filepath.ext(string)

state := lua.NewState()
Preload(state)
source := `
    local filepath = require("filepath")
    local result = filepath.ext("/var/tmp/file.name")
    print(result)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

.name

func FromSlash added in v0.5.0

func FromSlash(L *lua.LState) int

FromSlash returns the result of replacing each slash ('/') character in path with a separator character. Multiple slashes are replaced by multiple separators.

func Glob

func Glob(L *lua.LState) int

Glob: filepath.glob(pattern) returns the names of all files matching pattern or nil if there is no matching file.

Example

filepath.glob(string)

state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
    local filepath = require("filepath")
    local inspect = require("inspect")
    local result = filepath.glob("./*/*.lua")
    print(inspect(result, {newline="", indent=""}))
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

{ "test/test_api.lua" }

func IsAbs added in v0.5.0

func IsAbs(L *lua.LState) int

IsAbs reports whether the path is absolute.

func Join

func Join(L *lua.LState) int

Join lua fileapth.join(path, ...) joins any number of path elements into a single path, adding a Separator if necessary.

Example

filepath.basename(string)

state := lua.NewState()
Preload(state)
source := `
    local filepath = require("filepath")
    local result = filepath.join("var", "tmp", "file.name")
    print(result)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

var/tmp/file.name

func ListSeparator

func ListSeparator(L *lua.LState) int

ListSeparator lua filepath.list_separator() OS-specific path list separator

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Match added in v0.5.0

func Match(L *lua.LState) int

Match reports whether name matches the shell file name pattern.

func Preload

func Preload(L *lua.LState)

Preload adds filepath to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local filepath = require("filepath")

func Rel added in v0.5.0

func Rel(L *lua.LState) int

Rel returns a relative path

func Separator

func Separator(L *lua.LState) int

Separator lua filepath.separator() OS-specific path separator

func Split added in v0.5.0

func Split(L *lua.LState) int

Split splits path immediately following the final Separator, separating it into a directory and file name component.

func SplitList added in v0.5.0

func SplitList(L *lua.LState) int

func ToSlash added in v0.5.0

func ToSlash(L *lua.LState) int

ToSlash returns the result of replacing each separator character in path with a slash ('/') character. Multiple separators are replaced by multiple slashes.

func VolumeName added in v0.5.0

func VolumeName(L *lua.LState) int

VolumeName returns leading volume name. Given "C:\foo\bar" it returns "C:" on Windows. Given "\\host\share\foo" it returns "\\host\share". On other platforms it returns "".

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL