Search for Files

Hello,

I have written an application which could create (theoretically) an unlimited number of txt files. These all have individual names, based on the date & time when they were created.

Is there a way of browsing the “system.DocumentsDirectory” looking for all txt files (ie “*.txt”), and then returning a list / table of the results?

If not, does anyone have any ideas of how I could manage this?

Thanks [import]uid: 74250 topic_id: 14129 reply_id: 314129[/import]

Sadly, no there’s not a way to do it (outside of the simulator).

Here’s a link to folks that have tried some workarounds that may help. Otherwise, I think you’d have to either create a text file on your own indexing the files you’re creating or something to that effect. :frowning:

http://developer.anscamobile.com/forum/2010/09/21/there-function-obtain-file-directory-listing

-Mario [import]uid: 11636 topic_id: 14129 reply_id: 52001[/import]

Hello Mario,

Thank you for your reply.

I had a look at the link you gave, and Tom’s code (below) works great, but only on the simulator - not on the iPhone.

Tom’s code:
[lua] local dir = “’” … system.pathForFile( x, system.DocumentsDirectory ) … “’”
local fileDir = “’” … system.pathForFile( “_files.txt”, system.DocumentsDirectory ) … “’”
os.execute("ls " … dir … “>” … fileDir)[/lua]

I have no idea why this doesn’t work on the device, but it is a shame as it is brilliant on the simulator!
I think I will go with your idea of manually keeping track of every file my application creates.

Thanks again. [import]uid: 74250 topic_id: 14129 reply_id: 52041[/import]