[racket] reliable path comparison?

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Thu Oct 21 11:31:01 EDT 2010

On Thu, Oct 21, 2010 at 11:23 AM, scouic <scouic at gmail.com> wrote:
> Hi,
> i think that the problem is the \ character, because this works :
> #lang racket
> (equal? (regexp-replace* "\\\\" (path->string (build-path "C:\\")) "/")
>         (regexp-replace* "\\\\" (path->string (build-path "C:\\")) "/"))
>
> and returns true


Unfortunately, I'm occasionally getting paths where the entire path is
lowercased, and at other times, I'm getting it in mixed case: case
sensitivity is the issue I'm hitting.

The unsatisfactory solution I've got so far is:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; same-path?: path path -> boolean
;; Produces true if both paths are pointing to the same file.
(define (same-path? p1 p2)
  (cond
    [(eq? (system-path-convention-type) 'windows)
     (string=? (string-downcase (path->string (normalize-path p1)))
               (string-downcase (path->string (normalize-path p2))))]
    [else
     (string=? (path->string (normalize-path p1))
               (path->string (normalize-path p2)))]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Posted on the users mailing list.