Skip to content
IsaacShelton edited this page Nov 13, 2022 · 5 revisions

where

2.7/where.adept defines a cross-platform way of getting the running executable's location on Windows and MacOS.

Functions

  • 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/")

    On error, an empty string "" is returned.

    [view src]

Usage Example

This example reads a text file named "file.txt" piece by piece from the directory that the executable is in.

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)
    }
}
Clone this wiki locally