How do I make and run my own file extension?

Solution 1:

In short: you make your own file extension by applying whatever letters you want to the end of the file name. You run it by telling your OS what program should be called when you double-click on it.


Full explanation:

A file extension is actually just the letters after the file, there is nothing magical about the extension. A lot of files I have made when I'm on my Linux machines I have forgotten to even put the file extension on.

That being said, in Windows the file extension is how Windows determines what the file is. If you change the file extension of a .mp3 for example to a .png Windows will think it is a picture when it tries to open it. What Windows does is it looks at the extension and sends the file to an appropriate program related to that file. so .mp3 gets sent to iTunes, .png gets sent to Paint, .html gets sent to Firefox/Chrome, and .docx gets sent to Word.

In terms of the creation of these files, they fall into two categories. There are plain text files (.html, .txt, .java, .py, .cpp, .config, .xml) and then there are binary data files (.exe, .mp3, .png) (well, and then there are mixes of binary and plain text like .docx, but they can be treated like binary files). When you are dealing with plain text files (it is plain text if Notepad can open it) it is very easy to do. Depending on your programming language you basically just open a file and read/write strings to the file. With binary files, it gets a little more complicated, but the principle remains the same, you are reading/writing bytes from a file.

To make a file of a particular type executable (by double-clicking on it) is probably the hardest step depending on your programming language. If it is C or C++, you simply point Windows to your .exe and Windows sends the file you wish to open as the second argument in args to your program's main method. In Java or Python, it is still doable, but you'll have to work out some sort of workaround to get Windows to open the run-time environment or interpreter and send the file argument to the program.

Solution 2:

You will need to choose a programming language, then write a program which looks for files with an extension you have chossen. Those files must also be written so the program looking for them can read, understand and execute the code within.

Solution 3:

Assuming since you're talking about Warcraft III you're on Windows. Also assuming you're not wanting to do this programatically (otherwise you would have asked on stackoverflow).

Save a file with your custom extension. Open the file in Windows Explorer and it will ask you how to open it. Choose "pick from list", select the program you want, and check "Always use the selected program to open this kind of file". Voila, you can now "run" files with your custom extension.