Operating system for OpenComputers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
496B

  1. function os.chdir(p) -- string -- boolean string -- changes the current working directory of the calling process to the directory specified in *p*, returning true or false, error
  2. if not (p:sub(1,1) == "/") then
  3. local np = {}
  4. for k,v in pairs(fs.segments(os.getenv("PWD").."/"..p)) do
  5. if v == ".." then
  6. np[#np] = nil
  7. else
  8. np[#np+1] = v
  9. end
  10. end
  11. p = "/"..table.concat(np,"/")
  12. end
  13. if fs.list(p) then
  14. os.setenv("PWD",p)
  15. else
  16. return false, "no such directory"
  17. end
  18. end