tal/mod/fs.lua

28 lines
471 B
Lua
Raw Permalink Normal View History

2025-02-06 00:30:52 +00:00
local exports = {};
function exports.exists(path)
local f = io.open(path, "r");
if f == nil then return false end
if f:read(1) == nil then return false end
return true;
end
function exports.home()
return os.getenv "HOME";
end
function exports.pwd()
return os.getenv "PWD" or "./";
end
2025-02-06 15:46:02 +00:00
--- @param path string
2025-02-06 00:30:52 +00:00
function exports.ls(path)
2025-02-06 15:46:02 +00:00
local f = assert(io.popen("ls " .. path:quotesh()));
local res = f:read "*a";
f:close();
return res;
2025-02-06 00:30:52 +00:00
end
return exports;