For this particular purpose, you want `define-runtime-path`:
https://docs.racket-lang.org/reference/Filesystem.html#%28part._runtime-path%29

-Philip


On Mon, Jul 27, 2020 at 9:38 PM Peter W A Wood <[email protected]>
wrote:

> I have a short racket program/script that reads a file from the directory
> in which it is stored. The directory structure is something like this:
>
>         a/
>                 b/
>                         c/
>                                 my-racket.rkt
>                                 my-data-file.txt
>
> I want to be able to run the program from the command line no matter what
> is the current working directory. E.G.:
>
>         a> racket b/c/my-racket.rkt
>         a/b> racket c/my-racket.rkt
>         a/b/c> racket my-racket.rkt
>
> In order to do so, I need to provide the correct path to my-data-file.txt
> depending on from where the script was launched. I haven’t learnt about
> Racket modules yet so I resorted to searching Stack Overflow. I found a
> code snippet that I used which worked:
>
> (define script-dir (path-only (resolved-module-path-name
>   (variable-reference->resolved-module-path
>    (#%variable-reference)))))
>
> Is this the best way to ascertain the directory of the “current module”?
>
> Thanks in advance
>
> Peter
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/92DACE01-60C8-445A-A07E-A4E6A6F5F684%40gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAH3z3ga%2B4Lhvg8%3DitgW_aLZ%2B-RbdN%2BAZuPPPeYukD3qRYuPiBw%40mail.gmail.com.

Reply via email to