Many thanks Philip

The resulting code is much neater and, to me, more readable:

(define-runtime-path foo.txt "foo.txt")
(define-runtime-path bar.txt "bar.txt")
(define-runtime-path outfile.txt "outfile.txt")
(define-runtime-path Data/portfolio.csv "../../Data/portfolio.csv")
(define-runtime-path Data/portfolio.csv.gz "../../Data/portfolio.csv.gz”)

Peter

> On 28 Jul 2020, at 09:40, Philip McGrath <phi...@philipmcgrath.com> wrote:
> 
> For this particular purpose, you want `define-runtime-path`: 
> https://docs.racket-lang.org/reference/Filesystem.html#%28part._runtime-path%29
>  
> <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 <peterwaw...@gmail.com 
> <mailto:peterwaw...@gmail.com>> 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 racket-users+unsubscr...@googlegroups.com 
> <mailto:racket-users%2bunsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/92DACE01-60C8-445A-A07E-A4E6A6F5F684%40gmail.com
>  
> <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 racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/524F478B-0915-4C2F-874B-84CDB966B7D5%40gmail.com.

Reply via email to