Log In  

Cart [#54225#] | Code | 2018-07-17 | License: CC4-BY-NC-SA | Embed

I am trying to get a program to list the files in the current directory. The Wiki says that ls() outputs a table of the folder's contents, but it gives me a [NIL] for every item in the folder. Why is that? Does anyone know how to do this?
Thanks!

P#54226 2018-07-17 07:40 ( Edited 2018-07-17 12:45)

I think you're trying to index (incorrectly) from within the print command.

I've just tried this and it worked:

files=ls()
cls()
print("count: "..#files)
for file in all(files) do
 print(file)  -- no need to index here, as the "for" gives you the actual value
end
P#54227 2018-07-17 07:51 ( Edited 2018-07-17 11:51)

Thanks! That did the trick. That made me feel like a doofus.

P#54228 2018-07-17 08:45 ( Edited 2018-07-17 12:45)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-08-20 05:17 | 0.025s | 4194k | Q:25