2.7/where.adept defines a cross-platform way of getting the running executable's location on Windows and MacOS.
2.7/where.adept
func where() String
Returns the directory where the current executable resides in, followed by a slash/backslash.
(e.g. "C:\\Users\\isaac\\AdeptProjects\\AdeptMinesweeper\\", "/Users/isaac/Applications/Tangent.app/Contents/MacOS/")
"C:\\Users\\isaac\\AdeptProjects\\AdeptMinesweeper\\"
"/Users/isaac/Applications/Tangent.app/Contents/MacOS/"
On error, an empty string "" is returned.
""
[view src]
This example reads a text file named "file.txt" piece by piece from the directory that the executable is in.
"file.txt"
import where import basics func main { filename String = where() + "file.txt" filename_cstr *ubyte = filename.cstr() defer delete filename_cstr f *FILE = fopen(filename_cstr, 'r') unless f { printf("Failed to open file: \"%S\"\n", filename) return } defer fclose(f) buffer POD 256 ubyte = undef while fgets(&buffer as *ubyte, 256, f) { printf("%s", &buffer as *ubyte) } }
There was an error while loading. Please reload this page.
Table of Contents