How do I read the contents of a folder?

Hi, I have an app that save a bunch of txt files and I’d like to create a screen to show what files are there and let the user select which file they’d like to load.

Does anyone know how to load all the files names from a folder into a table? [import]uid: 12903 topic_id: 6997 reply_id: 306997[/import]

Because you create the files in the app, you can write them to a table while the app is running and write on exit to a file, or write to file as they are created, using “a” with the file write so as to append the file and not overwrite the last entry

then read the file holding the filenames and run through it
files = system.pathForFile( “filenames.txt”, system.DocumentsDirectory )

fnames = {}
– read the filenames into fnames
for line in io.lines(files) do–iterate through table
table.insert(fnames, line)–insert each line of file into table
print("filename ", line)
end
[import]uid: 2131 topic_id: 6997 reply_id: 24510[/import]

Thanks Rob. That’s a great way to handle that. I did some research on lua and it turns out there’s no way to read a directory in lua so this is a great way to step around that. [import]uid: 12903 topic_id: 6997 reply_id: 24511[/import]

no worries,
was in a similar situation recently myself,
glad I could be of help

comment by io.lines should be iterate through file not table

doh! [import]uid: 2131 topic_id: 6997 reply_id: 24514[/import]