Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help,
read this .
Ivo
Prole
Posts: 7 Joined: Sat Apr 05, 2014 10:05 pm
Contact:
Post
by Ivo » Tue Apr 22, 2014 9:03 pm
I want to write a function to get the path of a filename in a LÖVE program, and am finding it difficult. getDir('/usr/local/bin/sl') should return '/usr/local/bin'. I essentially want to remove the last item in a filename. In python I would just do:
Code: Select all
def getDir(sPath):
dir = '/'.join(sPath.split('/')[:-1])
return dir
but as far as I know lua does not have the split or the join functions.
slime
Solid Snayke
Posts: 3170 Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:
Post
by slime » Tue Apr 22, 2014 9:13 pm
Something like this:
Code: Select all
function getDir(filepath)
return filepath:match("(.+)/") or ""
end
It will return a string containing everything up to the last '/' in the filepath, or an empty string if there isn't any '/'.
Ivo
Prole
Posts: 7 Joined: Sat Apr 05, 2014 10:05 pm
Contact:
Post
by Ivo » Tue Apr 22, 2014 9:28 pm
worked perfectly, thanks!
Users browsing this forum: Google [Bot] and 3 guests