'VLC-LUA: using net.stat
I am trying to write a function that finds the first .waste dir in one of the parent dirs (e.g. .. ../.. ../../..).
For this I need to see if the dir exists. For that I would imagine net.stat
would be useful.
But this fails:
vlc.net.stat("/")
with:
lua warning: Error while running script /home/tange/.local/share/vlc/lua/extensions/WasteBasket.lua, function activate(): /home/tange/.local/share/vlc/lua/extensions/WasteBasket.lua:42: attempt to index field 'net' (a nil value)
From the error it almost looks as if vlc.net
does not contain vlc.net.stat
- but net.stat
is listed on:
https://www.videolan.org/developers/vlc/share/lua/README.txt
An example using net.stat
for VLC-LUA will be very appreciated.
Solution 1:[1]
I ended up using os.execute("cd " .. dir)
to see if a dir exists.
It works, but I regard it as a hack.
function directory_exists(dir)
-- Simple checker if dir exists
-- shell quote the dirname
dir, _ = dir:gsub("([\002-\009\011-\026\\#?`(){}%[%]^*<>=~|; \"!$&'\130-\255])", "\\%1")
dir, _ = dir:gsub("\n", "'\n'")
return os.execute("cd " .. dir)
end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ole Tange |