This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Nothy's profile picture

"Up" in a directory string formatting help

Started by Nothy, 07 September 2016 - 05:18 PM
Nothy #1
Posted 07 September 2016 - 07:18 PM
I've been fiddling around with the string library for a bit now, and I haven't found a way to go "up" in a directory using the string library.
Example:
Let's say you're in the directory "foo/bar" and you want to go up.
You'd want to end up in "foo/".
This is basically my problem, I can't get it to work.

Any tips or solution is more than appreciated.
KingofGamesYami #2
Posted 07 September 2016 - 07:22 PM
Why use the string library?
Nothy #3
Posted 07 September 2016 - 07:39 PM
That.. was surprisingly helpful. Thanks!
Nothy #4
Posted 07 September 2016 - 08:04 PM
Updaet:
If I use the "up" function with fs.getDir(string dir) then it will simply crash on me with the error: "No such file".
 
      if files == "/" then
        edge.log("F:"..fs.getDir(files))
      else
        if fs.exists(fs.getDir(files)) then

          files = fs.getDir(files)

          edge.log("F:"..fs.getDir(files))
          sleep(0.1)
          filebrowser()
        end
      end
And yes I'm doing some very heavy debugging.
Nothy #5
Posted 07 September 2016 - 08:31 PM
Got it to work. Just had to change

files = fs.getDir(files)
To

files = "/"..fs.getDir(files).."/"
Edited on 07 September 2016 - 06:33 PM