2019-11-06 14:28:40 +11:00
|
|
|
function os.chdir(p) -- changes the current working directory of the calling process to the directory specified in *p*, returning true or false, error
|
|
|
|
if not (p:sub(1,1) == "/") then
|
|
|
|
local np = {}
|
|
|
|
for k,v in pairs(fs.segments(os.getenv("PWD").."/"..p)) do
|
|
|
|
if v == ".." then
|
|
|
|
np[#np] = nil
|
|
|
|
else
|
|
|
|
np[#np+1] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
p = "/"..table.concat(np,"/")
|
|
|
|
end
|
2019-11-06 20:30:26 +11:00
|
|
|
if fs.list(p) then
|
2019-11-06 14:28:40 +11:00
|
|
|
os.setenv("PWD",p)
|
|
|
|
else
|
|
|
|
return false, "no such directory"
|
|
|
|
end
|
|
|
|
end
|