.txt only?

Hello all,

Is there any way around the restriction that text files used as Codea assets must have the .txt file extension? Any way, at least, to use the Lua io library to read files with other extensions? Thanks!

If I’m not mistaken, a file can have any .extension you want. It’s just that Codea on shows file names with .txt . The files will be there, you just don’t see them so you have to keep track of them yourself. If you put files in the Codea Dropbox folder and sync them with the Dropbox app, you should see the files there.

Hmm, ok. I’ve tried to put a text file - lets call it test.xyz - in my Dropbox folder from outside of Codea, then sync that folder from within Codea, as usual. It seems to detect a file there, since it will tell me 1 file remaining to sync, then 0. But, then if I try to use readtext(“Dropbox:test.xyz”), I get nil. I’ve tried it without writing out the .xyz extension in the readtext call but same. I also notice that if I hit the sync button again in my Codea assets, it will say 1 remaining, then 0, again - each time I try to sync.

I’m not sure if the io library should work from within Codea. I see some references to it here in the forum, but no one really using it.

Thanks!

@iam3o5am I’ll try playing around with it later once we’re done with the Christmas morning activities.

@iam3o5am Here’s some code I used to read a text file with a .xyz extension. I created the file in Dropbox and sync’d it with the Codea Dropbox folder. It didn’t show there which is what I expected, but I was able to read it and display the contents.

function setup()  
    file = os.getenv("HOME").."/Documents/Dropbox.assets/Test1.xyz"
    readTest(file)
end

function readTest(file)
    rfd=io.open(file,"r")
    print(rfd:read("*a"))  
end

Hi @iam3o5am - @dave1707 is quite right you can load text files and read and display them with Codea. @Ignatz and others use that method for .obj and .mtl model files. You can find the code in many projects. Dropbox doesn’t have to recognise the file type and it can be buried in subdirectories.

What may happen is if you are using a different text type, I think UTF8 is the standard format, or possibly you are using a system file type that is recognised and cant be read.

Thank you! I haven’t had the chance to get back to this - but I’m glad it works! I will give it a try again and let you know.

Finally getting back to this - thanks @dave1707. Now, is there any way to iterate over directory contents - in this case, all files in Dropbox.assets? It seems that io.popen is for that purpose, but is not supported in this environment. Any work-around that someone has figured out? I’d like to be able to scan the contents for files with a particular extension, without knowing in advance what the full filenames are. Thanks!

@iam3o5am I don’t think there’s a way or a least I haven’t seen any. On a PC there’s a Dir option that shows all the files in a directory, but I don’t there’s anything like that for Apple.

The ‘ls’ command lists directory contents for POSIX systems, which includes Apple OS’s. Not sure, though, if there is any way to leverage that from within Codea. That’s the crux of the issue.

Basically, I want a way to do what Codea’s assetList() function does, but for files with non-Codea-recognized file extensions.