Path produced by define-runtime-path does not work on Win(11)

Following the advice from one previous reply to my question, I'm now using (define-runtime-path ...), instead of (current-directory). This has solved one of my problems, namely, the program can now find "scribblings/math-quiz.html" file, wherever it is installed relative to the math-quiz module.
However, both define-runtime-path, and current-directory have the same problem on Windows (that is W11 - the only one I have here to test).
The path returned (when this is run as Package install from racket-lang.org), on W11 computer is with backslashes as in c:\dir\dir\...\scribblings\math-quiz.html
This seemed OK to me at first, but math-quiz would not display the html file, and would report the error that file can not be found. All the time on Linux (where I program anyway), the file was found because the path was reported as: /home/dir/dir.../scribblings/math-quiz.html.

My final code for opening HTML docs is this:

(define (fix-path path-str)
  (list->string
   (map (lambda (c) (case c
                      ((#\\) #\/)
                      (else c))) (string->list path-str))))

(define-runtime-path scribble-path "scribblings/math-quiz.html")

(define menu-item-html (new menu-item%
                            [label "HTML Documentation"]
                            [parent help-menu]
                            [callback
                             (lambda (mi e)
                               (send-url
                                (fix-path
                                 (path->string scribble-path))))]))

This works both on Linux and on Windows.
So, why does W11 accept Linux path string, but not the path string that Racket returns as windows path?

I think you should try send-url/file. The reason is that URIs (not filenames!) are encoded with forward slashes on Windows.

Yes, this works. Thanks for the explanation.

My first fix is like this:

(define-runtime-path scribble-path "scribblings")
(define scribble-path-string (path->string scribble-path))

(if (eq? (system-type) 'windows)
    (set! scribble-path-string
          (string-append scribble-path-string "\\math-quiz.html"))
    (set! scribble-path-string
          (string-append scribble-path-string "/math-quiz.html")))

(define menu-item-html (new menu-item%
                            [label "HTML Documentation"]
                            [parent help-menu]
                            [callback
                             (lambda (mi e)
                               (send-url/file scribble-path-string))]))

But after further testing on W11, I found that even this works (forcing unix / slash at the end of windows path that starts with backslashes).

(define-runtime-path scribble-path "scribblings/math-quiz.html")
(define scribble-path-string (path->string scribble-path))

(define menu-item-html (new menu-item%
                            [label "HTML Documentation"]
                            [parent help-menu]
                            [callback
                             (lambda (mi e)
                               (send-url/file scribble-path-string))]))

Anyway, I will stay with the first solution, just to be safe.

1 Like