Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0

filesystem.list() function help


I want to get an array of all the files under a certain directory, but I don't know how to use this function as there isn't really much explanation on the internet about the specifics of implementing this into code. I don't really know what I'm supposed to do to get the information out of this so called "function value". I was hoping someone could tell me how to use this to list the directories into an and maybe give an example code.

Share this post

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0
local function list_files(dir)
  local files = {}
  for path, err in filesystem.list(dir) do
    assert(path, err)
    if not filesystem.isDirectory(path) then
      table.insert(files, path)
  return files

-- # use
local files = list_files '/home'
-- # example result
-- {
--	'test.lua',
--	'poop.cfg'
-- }


Share this post

Link to post
Share on other sites
  • 0

Your code worked when I ran a small test program with it thanks, but sadly I can't put it in my main program yet. I don't think it's your code's doing, but when I run my program, I get a blue screen for "Unrecoverable Error. bad argument #2 (number expected, got number)" Would you happen to know what would cause that confusing error?


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.