Currently works only on NIX (Linux, BSD, UNIX etc.) Maybe it will work on Mac since Mac is based on BSD, I have no way of testing. It will for sure not work on Windows currently. If you need it to work, let me know I can probably make that happen.
Module depands on nix commands test
and realpath
There are tests for all commands. One test appears to fail even know the result is as expected. Still working on figuring that out; any help would be welcome.
bool = path.is.dir(string)
bool = path.is.folder(string)
bool = path.is.file(string)
bool = path.is.symlink(string)
bool = path.is.pipe(string)
bool = path.is.socket(string)
bool = path.is.character(string)
bool = path.is.block(string)
bool = path.can.read(string)
bool = path.can.write(string)
bool = path.can.run(string)
bool = path.can.exec(string) // ALIAS OF can.run
string = path.get.abs(string)
string = path.get.dirname(string)
string = path.get.filename(string)
string = path.get.ext(string)
table = path.list.all(string)
table = path.list.folders(string)
table = path.list.dirs(string) // ALIAS OF list.folders
table = path.list.files(string)
table = path.list.by_ext(filepath, ext)
table = path.list.split(string)
table = path.list.ext(string)
table = path.list.file_ext(string) // ALIAS OF list.ext
bool = path.exists(string)
string = path.append(filepath, file)
string, string, string = path.split(string) // -> dir, file, ext
string = path.realpath(string)
This is my first Lua program/module, well right after Hello World
.
Any suggestions are more then welcome.
Run following in your Lua project folder.
git clone https://github.com/luatamer/path.git
Get all path
commands
local path = require('path')
if path.is.dir(os.getenv("PWD"))
then
print('INF Success')
else
print('ERR Failed')
end
Get only is
commands
local is = require('path').is
if is.dir(os.getenv("PWD"))
then
print('INF Success')
else
print('ERR Failed')
end
filepath is.string All args in this module must be a string, if unsure check first with is.string
Append file or folder to path, adds seperator if needed
checks if filepath exists
filepath exists and is a filesytem directory/folder
alias for is.dir
filepath exists and is a filesytem file
filepath exists and is symbolic link
filepath exists and is a pipe
filepath exists and is socket
filepath exists and is character special
filepath exists and is block special
filepath exists and we can read the filepath
filepath exists and we can write to the filepath
filepath exists and we can run/execute the filepath
filepath exists and we can run/execute the filepath
list all files and folders at given filepath
list all files at given filepath
list all files at given filepath by extention
list all file extentions
path.list.ext('archive.tar.gz')
--> {"tar", "gz"}
list all folders at given filepath
list all folders at given filepath
Will return 3 items, works also on windows Does not verify paths existens
string, string, string = path.spilt(string)
folder, filename, extention = path.spilt("/tmp/test.lua.txt")
-> /tmp/ test.lua.txt txt
returns filename including extention discarding folder/directory Returned value will be a filesystem file OR NIL
returns absolute directory/folder path discarding filename. Returned value will be a filesystem directory/folder OR NIL
returns filename including extention discarding folder/directory Returned value will be a filesystem file OR NIL
Returns the file extention from the given filepath if exists
Print the resolved absolute file name; all but the last component must exist
realpath: [filepath]: No such file or directory ]]