This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TyDoesMC's profile picture

How would I declare my own file extensions

Started by TyDoesMC, 02 March 2015 - 04:38 PM
TyDoesMC #1
Posted 02 March 2015 - 05:38 PM
Hello, been awhile sense I coded and was wondering how would I make a program that checks for a folder in the programs folder of that computer and then check for 1 .CONFIG and .DLL (just examples) I'm trying to make a very configurable program dunno what yet but this will be used in most of my newer programs.
SquidDev #2
Posted 02 March 2015 - 05:46 PM
I'm slightly confused, but I think you are looking for fs.find?

For instance:


local files = fs.find(shell.resolve("*.config"))
print(textutils.serialize(files))

This will find all ".config" files in a directory, though this is case sensitive. Otherwise you can iterate through the result of fs.list, string.lower each one and check if it ends in .config.

On a practical note I wouldn't use .dll as that actually means something and so would be confusing for the user if they are trying to open it in Windows Explorer.
Edited on 02 March 2015 - 04:46 PM
TyDoesMC #3
Posted 02 March 2015 - 05:52 PM
Basically im trying to make my programs files have an extension like .exe instead of being just the name and have add-on's like one big program and then add .pkg to my folder and it would activate features, I'm sorry if this is confusing.

Let me explain.
I'm trying to make 1 program.
I'm going to develop add-on's: (.pkg) and you add them to a folder in /computer/ID/MYPROGRAMFOLDER/Addon.pkg
then a config will be all the variables in side the main program so like "password = "Pass"" that would be in a file called config.cfg in side the addon folder above.
Lupus590 #4
Posted 02 March 2015 - 11:00 PM
My suggestion would be to try to be either compatible with existing IRL OS extentions (I.E. use .lua as your program extension) or try to make your own extension (tip, go all egotistical and put your initials/name/username at the front). Like SquidDev said, avoid thinks that will confuse IRL OS's.

Also, you are not limited to 3 or 4 characters, although shorter is easier. Also, the extension is like any other part of the file name, it just helps OS and user identify the file type.

As for the code, SquidDev covered everything you should need for filtering and viewing.
Edited on 02 March 2015 - 10:03 PM