minetest.get_dir_list(path, [is_dir])

User avatar
Tmanyo
Member
 
Posts: 151
Joined: Mon Sep 29, 2014 01:20
GitHub: Tmanyo
IRC: Tmanyo
In-game: tmanyo

minetest.get_dir_list(path, [is_dir])

by Tmanyo » Mon Jul 18, 2016 00:43

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.
Tmanyo
http://rrhmsservers.weebly.com/
Servers I Host:
Xtremetest
Vault-81
 

User avatar
octacian
Member
 
Posts: 408
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian

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

by octacian » Mon Jul 18, 2016 14:58

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.
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 

User avatar
Krock
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

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

by Krock » Mon Jul 18, 2016 15:17

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
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

User avatar
octacian
Member
 
Posts: 408
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian

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

by octacian » Mon Jul 18, 2016 15:21

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...
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

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

by Byakuren » Mon Jul 18, 2016 20:23

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.
Every time a mod API is left undocumented, a koala dies.
 

User avatar
octacian
Member
 
Posts: 408
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian

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

by octacian » Mon Jul 18, 2016 21:05

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
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

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

by Byakuren » Mon Jul 18, 2016 21:57

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
Every time a mod API is left undocumented, a koala dies.
 

User avatar
Tmanyo
Member
 
Posts: 151
Joined: Mon Sep 29, 2014 01:20
GitHub: Tmanyo
IRC: Tmanyo
In-game: tmanyo

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

by Tmanyo » Tue Jul 19, 2016 00:40

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.
Tmanyo
http://rrhmsservers.weebly.com/
Servers I Host:
Xtremetest
Vault-81
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

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

by rubenwardy » Tue Jul 19, 2016 02:48

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().
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron