Page 1 of 1

minetest.get_dir_list(path, [is_dir])

PostPosted: Mon Jul 18, 2016 00:43
by Tmanyo
Is it possible to use minetest.get_dir_list(path, [is_dir]) in a formspec for textlist. I want to list the contents of a certain folder on the same mod.

Re: minetest.get_dir_list(path, [is_dir])

PostPosted: Mon Jul 18, 2016 14:58
by octacian
The best thing I've seen is if not os.execute("ls <dir>") then os.execute("dir <dir>") end. Never heard of get_dir_list, in fact, I don't think it exists.

Re: minetest.get_dir_list(path, [is_dir])

PostPosted: Mon Jul 18, 2016 15:17
by Krock
You can do it like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local formspec = "textlist[0,0;7,5;mydir_list;"
local files = minetest.get_dir_list("PATH")
for i = 1, #files do
   formspec = formspec .. files[i] .. ","
end
formspec = formspec .. "]"

endev15: https://github.com/minetest/minetest/bl ... .txt#L1826

Re: minetest.get_dir_list(path, [is_dir])

PostPosted: Mon Jul 18, 2016 15:21
by octacian
Krock wrote:You can do it like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local formspec = "textlist[0,0;7,5;mydir_list;"
local files = minetest.get_dir_list("PATH")
for i = 1, #files do
   formspec = formspec .. files[i] .. ","
end
formspec = formspec .. "]"

endev15: https://github.com/minetest/minetest/bl ... .txt#L1826


Thanks! I didn't see it in the dev wiki, so... I actually really need this for my computer mod, and it's definitely more stable then os.execute. From what I see, this returns an array and then you cycle through the array to create the list? I guess I could to the same thing for textareas, couldn't I...

Re: minetest.get_dir_list(path, [is_dir])

PostPosted: Mon Jul 18, 2016 20:23
by Byakuren
endev15 wrote:
Krock wrote:You can do it like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local formspec = "textlist[0,0;7,5;mydir_list;"
local files = minetest.get_dir_list("PATH")
for i = 1, #files do
   formspec = formspec .. files[i] .. ","
end
formspec = formspec .. "]"

endev15: https://github.com/minetest/minetest/bl ... .txt#L1826


Thanks! I didn't see it in the dev wiki, so... I actually really need this for my computer mod, and it's definitely more stable then os.execute. From what I see, this returns an array and then you cycle through the array to create the list? I guess I could to the same thing for textareas, couldn't I...

You should check lua_api.txt, since it is more complete than the wiki.

Re: minetest.get_dir_list(path, [is_dir])

PostPosted: Mon Jul 18, 2016 21:05
by octacian
Byakuren wrote:You should check lua_api.txt, since it is more complete than the wiki.


Yeah, I should. Will try and make that more of a habit. Maybe I'll invent some way to format it nicely... Some type of "API Display Program." LOL

Re: minetest.get_dir_list(path, [is_dir])

PostPosted: Mon Jul 18, 2016 21:57
by Byakuren
endev15 wrote:
Byakuren wrote:You should check lua_api.txt, since it is more complete than the wiki.


Yeah, I should. Will try and make that more of a habit. Maybe I'll invent some way to format it nicely... Some type of "API Display Program." LOL

Here is a formatted version too: http://rubenwardy.com/minetest_modding_ ... a_api.html

Re: minetest.get_dir_list(path, [is_dir])

PostPosted: Tue Jul 19, 2016 00:40
by Tmanyo
Krock wrote:You can do it like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local formspec = "textlist[0,0;7,5;mydir_list;"
local files = minetest.get_dir_list("PATH")
for i = 1, #files do
   formspec = formspec .. files[i] .. ","
end
formspec = formspec .. "]"

endev15: https://github.com/minetest/minetest/bl ... .txt#L1826

Thank you Krock.

Re: minetest.get_dir_list(path, [is_dir])

PostPosted: Tue Jul 19, 2016 02:48
by rubenwardy
Krock wrote:You can do it like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local formspec = "textlist[0,0;7,5;mydir_list;"
local files = minetest.get_dir_list("PATH")
for i = 1, #files do
   formspec = formspec .. files[i] .. ","
end
formspec = formspec .. "]"

endev15: https://github.com/minetest/minetest/bl ... .txt#L1826


It would be much better to do this:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local files = minetest.get_dir_list("PATH")
local formspec = "textlist[0,0;7,5;mydir_list;" .. table.concat(files, ",") .. "]"


or even:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local formspec = "textlist[0,0;7,5;mydir_list;" .. table.concat(minetest.get_dir_list("PATH"), ",") .. "]"



Please note that if you're going to access dirs/files outside of the world dir or you mod dir, you need to use request_insecure_environment().