{"id":13699742,"url":"https://github.com/starwing/lpath","last_synced_at":"2025-07-13T05:40:32.992Z","repository":{"id":1277213,"uuid":"4569687","full_name":"starwing/lpath","owner":"starwing","description":"a OS specified path manipulation module for Lua","archived":false,"fork":false,"pushed_at":"2023-06-08T07:20:05.000Z","size":203,"stargazers_count":44,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-27T16:42:12.787Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/starwing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2012-06-06T06:59:34.000Z","updated_at":"2024-12-22T13:39:59.000Z","dependencies_parsed_at":"2023-07-08T10:46:39.348Z","dependency_job_id":null,"html_url":"https://github.com/starwing/lpath","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/starwing/lpath","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starwing%2Flpath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starwing%2Flpath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starwing%2Flpath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starwing%2Flpath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/starwing","download_url":"https://codeload.github.com/starwing/lpath/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starwing%2Flpath/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265096555,"owners_count":23710775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T20:00:42.744Z","updated_at":"2025-07-13T05:40:32.944Z","avatar_url":"https://github.com/starwing.png","language":"Lua","funding_links":[],"categories":["Bibliotecas"],"sub_categories":[],"readme":"lpath - Path utils for Lua\n==========================\n[![CI](https://github.com/starwing/lpath/actions/workflows/test.yml/badge.svg)](https://github.com/starwing/lpath/actions/workflows/test.yml)[![Coverage Status](https://coveralls.io/repos/github/starwing/lpath/badge.svg?branch=master)](https://coveralls.io/github/starwing/lpath?branch=master)\n\n`lpath` is a [lfs](http://keplerproject.github.io/luafilesystem/)-like Lua module to handle path, file system and file informations.\n\nThis module is inspired by Python's `os.path` and `pathlib` module. It split into 4 parts:\n\n- `path`: main module, pathlib style path operations.\n- `path.fs`: fs specific operations, folder walking, file operations, etc.\n- `path.info`: some constants about path literals.\n- `path.env` set/get environment variables, and expand env vars in path.\n\nAll routines in this module which accept `...` for parameters means you could pass any count of `string` as arguments. All `string` will joined into a single path, just as pass all arguments to `path(...)`, and pass the resulting path string to the routine.\n\nAll routines may returns `nil, error` for error case. if you want raise error to Lua, use `assert(...)` for routines.\n\n## Usage\n\n### `path`\n\n| routine                         | return value | description                                                  |\n| ------------------------------- | ------------ | ------------------------------------------------------------ |\n| `path(...)`                     | `string`     | return joined normalized path string.                        |\n| `path.ansi()`                   | `none`       | set path string encoding to local code page.                 |\n| `path.ansi(number)`             | `none`       | set the code page number for path string encoding.           |\n| `path.ansi(string)`             | `string`     | convert UTF-8 `string` to current code page encoding.        |\n| `path.utf8()`                   | `none`       | set path string encoding to UTF-8.                           |\n| `path.utf8(string)`             | `string`     | convert current code page encoding `string` to UTF-8.        |\n| `path.alt(...)`                 | `string`     | return joined normalized path string using alternative sep.  |\n| `path.abs(...)`                 | `string`     | returns the absolute path for joined parts.                  |\n| `path.rel(path[, dir])`         | `string`     | returns  the relation path for dir (default for current work directory). |\n| `path.fnmatch(string, pattern)` | `boolean`    | returns whether the `pattern` matchs the `string`.           |\n| `path.match(path, pattern)`     | `boolean`    | returns as `path.fnmatch`, but using Python path matching rules. |\n| `path.drive(...)`               | `string`     | returns  the drive part of path.                             |\n| `path.root(...)`                | `string`     | returns the root part of path. (`\\` on Windows, `/` or `//` on POSIX systems.) |\n| `path.anchor(...)`              | `string`     | same as `path.drive(...) .. path.root(...)`                  |\n| `path.parent(...)`              | `string`     | returns the parent path for path.                            |\n| `path.name(...)`                | `string`     | returns the file name part of the path.                      |\n| `path.stem(...)`                | `string`     | returns the file name part without suffix name of the path.  |\n| `path.suffix(...)`              | `string`     | returns  the suffix name of the path.                        |\n| `path.suffixes(...)`            | `iteraotr`   | returns  a `idx`, `suffix` iterator to get suffix names of the path. |\n| `path.parts(...)`               | `iterator`   | returns  a `idx`, `part` iterator to get parts in the path.  |\n| `path.exists(...)`              | `boolean`    | returns whether the path is exists in file system (same as `fs.exists()`) |\n| `path.resolve(...)`             | `string`     | returns the path itself, or the target path if path is a symlink. |\n| `path.cwd()`                    | `string`     | fetch the current working directory path.                    |\n| `path.bin()`                    | `string`     | fetch the current executable file path.                      |\n| `path.isdir(...)`               | `boolean`    | returns whether the path is a directory.                     |\n| `path.islink(...)`              | `boolean`    | returns whether the path is a symlink.                       |\n| `path.isfile(...)`              | `boolean`    | returns whether the path is a regular file.                  |\n| `path.ismount(...)`             | `boolean`    | returns whether the path is a mount point.                   |\n\n### `path.fs`\n\n| routine                               | return value | description                                                  |\n| ------------------------------------- | ------------ | ------------------------------------------------------------ |\n| `fs.dir(...)`                         | `iterator`   | returns a iterator `filename, type` to list all child items in path. |\n| `fs.scandir(...[, depth])`            | `iterator`   | same as `fs.dir`, but  walk into sub directories recursively. |\n| `fs.glob(...[, depth])`               | `iterator`   | same as `fs.scandir`, but accepts a pattern for filter the items in directory. |\n| `fs.chdir(...)`                       | `string`     | change current working directory and returns the path, or `nil` for error. |\n| `fs.mkdir(...)`                       | `string`     | create directory.                                            |\n| `fs.rmdir(...)`                       | `string`     | remove empty directory.                                      |\n| `fs.makedirs(...)`                    | `string`     | create directory recursively.                                |\n| `fs.remvoedirs(...)`                  | `string`     | remove all items in a directory recursively.                 |\n| `fs.unlockdirs(...)`                  | `string`     | add write perimission for all files in a directory recursively. |\n| `fs.tmpdir(prefix)`                   | `string`     | create a tmpdir and returns it's path                        |\n| `fs.ctime(...)`                       | `integer`    | returns the creation time for the path.                      |\n| `fs.mtime(...)`                       | `integer`    | returns the modify time for the path.                        |\n| `fs.atime(...)`                       | `integer`    | returns the access time for the path.                        |\n| `fs.size(...)`                        | `integer`    | returns the file size for the path.                          |\n| `fs.touch(...[, atime[, mtime]])`     | `string`     | update the access/modify time for the path file, if file is not exists, create it. |\n| `fs.remove(...)`                      | `string`     | delete file.                                                 |\n| `fs.copy(source, target)`             | `boolean`    | copy file from the source path to the target path.           |\n| `fs.rename(source, target)`           | `boolean`    | move file from the source path to the target path.           |\n| `fs.symlink(source, target[, isdir])` | `boolean`    | create a symbolic link from the source path to the target path. |\n| `fs.exists(...)`                      | `boolean`    | same as `path.exists`                                        |\n| `fs.getcwd()`                         | `string`     | same as `path.cwd()`                                         |\n| `fs.binpath()`                        | `string`     | same as `path.bin()`                                         |\n| `fs.is{dir/link/file/mount}`          | `string`     | same as correspond routines in `path` module.                |\n\n#### `fs.dir()`/`fs.scandir()`/`fs.glob()`\n\nThese functions will return a iterator that yields  `filename`, `type` pair.  The `type` could be:\n\n- `\"file\"` a file name\n- `\"dir\"` a dir the will not walk into it.\n- `\"in\"` a dir that will walk into it, i.e. the next iteration will yields the content in this folder.\n- `\"out\"` a dir that completed walk.\n\nIf you pass a number argument as the *last* argument of `fs.scandir()`/`fs.glob()`, this number argument will be treat as the limit  of walking. e.g. `fs.scandir(\"foo\", 1)` will walks into all subdirectory/files in `\"foo\"`, but not contents in subdirectories.\n\n```lua\n-- assume folder \"foo\" has this struture:\n-- - foo\n--   |- bar\n--      |- bar.txt\n--   |- foo.txt\n-- the code below:\nfor fn, ty in fs.scandir(\"foo\", 1) do\n  print(fn, ty)\nend\n-- will prints:\n-- foo in\n-- bar dir\n-- foo.txt file\n-- foo out\n```\n\n`fs.glob()` accepts a path thats contains patterns in it. But patterns in `drive` part will be ignored. e.g. the pattern likes `\"*:/foo.txt\"` in Windows will yields empty results.\n\nA empty pattern (`\"\"`) is not allowed.\n\nIf a pattern contains `\"**\"`, the `fs.glob()` will walks into all current subdirectories to find a match after `\"**\"`, e.g. `\"**/*.txt\"` will yields all `.txt` files in any levels of subdirectories of current folder.\n\nIf the pattern ends with `\"**\"`, all subdirectories, but not files, will returnd.\n\nSome examples:\n\n```lua\n-- assume same struture of folder \"foo\" above.\nlocal function collect(pattern) do\n    local t = {}\n    for fn in fs.glob(pattern) do\n      t[#t+1] = fn\n    end\nend\ncollect \"*.txt\"    -- returns {\"foo/foo.txt\"}\ncollect \"**/*.txt\" -- returns {\"foo/foo.txt\", \"foo/bar/bar.txt\"}\ncollect \"**\"       -- returns {\"foo/bar\"}\n```\n\n\n\n### `path.env`\n\n| routine               | return value  | description                                                  |\n| --------------------- | ------------- | ------------------------------------------------------------ |\n| `env.get(key)`        | `string`      | fetch a environment variable value.                          |\n| `env.set(key, value)` | `string`      | set the environment variable value and returns the new value. |\n| `env.expand(...)`     | `string`      | return a path that all environment variables replaced.       |\n| `env.uname()`         | `string`, ... | returns the informations for the current operation system.   |\n\n### `path.info`\n\n`path.info` has several constants about current system:\n\n  - `platform`:\n      - `\"windows\"`\n      - `\"linux\"`\n      - `\"macosx\"`\n      - `\"android\"`\n      - `\"posix\"`\n  - `sep`: separator of directory on current system. It's `\"\\\\\"` on Windows, `\"/\"` otherwise.\n  - `altsep`: the alternative directory separator, always `\"/\"`.\n  - `curdir`: the current directory, usually `\".\"`.\n  - `pardir`: the parent directory, usually `\"..\"`.\n  - `devnull`: the null device file, `\"nul\"` on Windows, `\"dev/null\"` otherwise\n  - `extsep`: extension separator, usually `\".\"`.\n  - `pathsep`: the separator for $PATH, `\";\"` on Windows, otherwise `\":\"`.\n\n## License\n\nSame as Lua's License.\n\n## Build\n\nSee here: http://lua-users.org/wiki/BuildingModules\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarwing%2Flpath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstarwing%2Flpath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarwing%2Flpath/lists"}