[plt-scheme] Loading at runtime
On 10/6/07, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> If you really want to manually find file relative to the executable,
> though, then try
>
> (find-executable-path (find-system-path 'exec-file)
> "filename.dat")
(find-system-path 'exec-file)
gives me something down in the Mac application bundle, so I need to
pop back up out to get to the datafile that is adjacent to the
executable (bundle).
I ended up with something between the suggestions from Robby and Matthew.
(define (dyn-file fname)
(let-values ([(base name x)
(split-path
(find-executable-path
(find-system-path 'exec-file)))])
(case (system-type)
[(macosx)
(simplify-path
(build-path base 'up 'up 'up fname))]
[(windows) '...])))
That feels ugly for what I'm trying to do. That said, this gets me to
a datafile that a user is going to modify, and the application will
load data from that file at run-time. And for now, I'm "hard-coding"
the fact that, no matter where the application lives, the datafile
will be adjacent to the executable. Perhaps I should just pop open a
'File Open' dialog and be done with it... but this will do for the
task at hand, I think.
Thanks for the pointers; I wasn't about to stumble on the correct
one-two combo on my own.
Thanks,
Matt