C
C#13mo ago
rapid

Making an interpreter read custom filename extensions

I made an interpreter in Visual Studio (C#) for my own language. My question is, how do I make it so the interpreter runs every time I open a file with .baobi as the filename extension?
13 Replies
rapid
rapidOP13mo ago
Basically, I need the contents of the file to be assigned to a string in my interpreter script called "code" and then let the script do its thing. PS: I am relatively new to C#, so sorry for articulating some sentences weirdly.
Thinker
Thinker13mo ago
every time I open a file
How do you want this to work? Inside Visual Studio?
rapid
rapidOP13mo ago
is it possible for me to just open a .baobi from my desktop and have the script run?
Thinker
Thinker13mo ago
Yes, you can use file associations to set what program opens files with certain file extensions. You could for instance set the extension .baobi to open with a console app you've made which runs your interpreter.
rapid
rapidOP13mo ago
perfect!! and how..?
canton7
canton713mo ago
(Those are a Windows thing, and they're set up in the registry. Or you can right-click, Open With) Then if you select "Choose another app", you can browse to your exe and click "always" Your exe will be launched, and the path to the file will be passed as args[0]
rapid
rapidOP13mo ago
how do i get the .exe file of a visual studio console app?
canton7
canton713mo ago
It'll be in bin/?
rapid
rapidOP13mo ago
oh
Thinker
Thinker13mo ago
Or you could publish it as a single file, if you want to distribute it
rapid
rapidOP13mo ago
yes!! but how do read the .baobi file
canton7
canton713mo ago
The path to the .baobi file is passed as args[0] in your Main method You can then read it with any of the File I/O methods. File.ReadAllText will read the entire file into a string
rapid
rapidOP13mo ago
great! ill do all of this when i get home, thanks for the help!
Want results from more Discord servers?
Add your server