Log In  

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


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]

Follow Lexaloffle:          
Generated 2024-04-18 22:59:35 | 0.010s | Q:17