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

fs.getBase()

Started by Mrblahblah200, 11 December 2012 - 09:16 AM
Mrblahblah200 #1
Posted 11 December 2012 - 10:16 AM
Is there a better way of getting the base of a filepath than this?
string.reverse(string.sub(string.reverse(filepath),string.len(fs.getName(filepath)+1)
Thanks is advance!
CoolisTheName007 #2
Posted 11 December 2012 - 11:08 AM
This:

---returns directory from filepath @s
--according to CC, the root directory is '/', and here it's the same
function getDir(s)
return string.match(s,'^(.*)/') or '/'
end
MysticT #3
Posted 11 December 2012 - 11:56 AM
Or this:

function getDir(path)
  return string.sub(path, 1, #path - #fs.getName(path))
end