Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i get directory path, given a file name in Lua, which is platform independent

Tags:

lua

If file is /etc/haproxy/haproxy.cfg, output should be directory name /etc/haproxy.

Currently i am using

file = "/etc/haproxy/haproxy.cfg"
sep = "/"
file:match("(.*"..sep..")")

But it is not platform independent and would fail on Windows, since the path separator is different. So is there a platform agnostic way of achieving this, with using lfs module?

like image 688
ajays20078 Avatar asked Feb 06 '23 17:02

ajays20078


1 Answers

package.config:sub(1,1) gives you the path separator for the platform in which Lua is running. See the manual.

like image 116
lhf Avatar answered Feb 09 '23 08:02

lhf